1

/* This is a test that fails right now. Because we called "coffins.import" once in the server tests, and once in the client tests, and they imported the same csv file twice. WHAT SHOULD WE DO ABOUT THAT? */

it("There should be NO DUPLICATE coffins", function(done) {
        const allCoffins = Coffins.find();
   // What is unique in a coffin? Well, the bib_num is surely unique.
   // So no two coffins should have the same bib_num.
   // make an array of all bib_nums.

        const bib_nums = [];
        allCoffins.forEach(function(coffin){

   // is this coffin's bib_num already in our array? shouldn't be.

        assert.ok(bib_nums.indexOf(coffin.bib_num) === -1, "bib_num should be unique");

  // then put this bib_num in our list

        bib_nums.push(coffin.bib_num);

            console.log(bib_nums);
        });

  // if we got through the list with no assertion failures, its good.

       done();
    });

This the result of my failed test!

AndrewE
  • 11
  • 2
  • 1
    Well the "unit test" should really be making sure that a ["unique index"](https://docs.mongodb.com/manual/core/index-unique/) was put in place for the key(s) that is/are supposed to be "unique". Having a unique index in place enforces that there can be no duplicates in the first place. Of course [you need to get rid of them beforehand](https://stackoverflow.com/a/29072504/2313887), buy once you do the index looks after itself. – Neil Lunn Aug 10 '17 at 21:32

0 Answers0