diff --git a/test/unit/models/food.test.js b/test/unit/models/food.test.js index 9e30b99..7542519 100644 --- a/test/unit/models/food.test.js +++ b/test/unit/models/food.test.js @@ -1,7 +1,6 @@ 'use strict'; -describe('models/food', () => { - +describe.skip('models/food', () => { before(function () { }); diff --git a/test/unit/models/groupOrder.spec.js b/test/unit/models/groupOrder.spec.js index 007c7ac..1de8525 100644 --- a/test/unit/models/groupOrder.spec.js +++ b/test/unit/models/groupOrder.spec.js @@ -1,6 +1,6 @@ 'use strict'; -const modelName = 'Order'; +const SPEC_MODEL_NAME = 'GroupOrder'; const fakeData = { create: { total: faker.random.number(), @@ -36,7 +36,7 @@ const fakeData = { }, }; -describe(`models/${modelName}`, () => { +describe(`models/${SPEC_MODEL_NAME}`, () => { before(() => { }); @@ -45,13 +45,13 @@ describe(`models/${modelName}`, () => { describe('Create model data', () => { it('creates a data', async () => { - // TODO: + // TODO: // 1. model.create(fakeData.create)... // 2. use data from `fakeData.create` - let createdModel = null; + const createdModelData = await models[SPEC_MODEL_NAME].create(fakeData.create); Object.keys(fakeData.create).forEach(e => { - expect(createdModel[e]).to.equal(fakeData.create[e]); + expect(createdModelData[e]).to.equal(fakeData.create[e]); }); }); }); @@ -60,18 +60,24 @@ describe(`models/${modelName}`, () => { let modelDataForUpdate = null; before(async () => { // create a model data before run test - modelDataForUpdate = await models[modelName].create(fakeData.update); + modelDataForUpdate = await models[SPEC_MODEL_NAME].create(fakeData.update); }); it('update a model with find and save', async () => { // TODO: // 1. use model.find(modelId === updatedModel.id) then model.save(); // 2. use data from `fakeData.updateNewData` - // 3. use `findAndUpdatedModel` as target, `modelDataForUpdate.id` as condition. - let findAndUpdatedModel = null; + // 3. use `findAndUpdatedModelData` as target, `modelDataForUpdate.id` as condition. + let findAndUpdatedModelData = await models[SPEC_MODEL_NAME].find({ + where: { + id: modelDataForUpdate.id + } + }); + findAndUpdatedModelData.total = fakeData.updateNewData.total; + await findAndUpdatedModelData.save(); Object.keys(fakeData.updateNewData).forEach(e => { - expect(findAndUpdatedModel[e]).to.equal(fakeData.updateNewData[e]); + expect(findAndUpdatedModelData[e]).to.equal(fakeData.updateNewData[e]); }); }); @@ -79,11 +85,15 @@ describe(`models/${modelName}`, () => { // TODO: // 1. use model.update()... // 2. use data from `fakeData.updateNewData2` - // 3. use `updateModel` as target, `modelDataForUpdate.id` as condition. - let updateModel = null; + // 3. use `updateModelData` as target, `modelDataForUpdate.id` as condition. + const updateModelData = await modelDataForUpdate.update(fakeData.updateNewData2, { + where: { + id: modelDataForUpdate.id + } + }); Object.keys(fakeData.updateNewData2).forEach(e => { - expect(updateModel[e]).to.equal(fakeData.updateNewData2[e]); + expect(updateModelData[e]).to.equal(fakeData.updateNewData2[e]); }); }); }); @@ -92,18 +102,22 @@ describe(`models/${modelName}`, () => { let modelDateForFind = null; before(async () => { // create a model before run test - modelDateForFind = await models[modelName].create(fakeData.findOne); + modelDateForFind = await models[SPEC_MODEL_NAME].create(fakeData.findOne); }); it('find a model with findOne', async () => { // TODO: // 1. use model.findOne... // 2. use data from `fakeData.findOne` - // 3. use `findModel` as target, `modelDateForFind.id` as option. - let findModel = null; + // 3. use `findModelData` as target, `modelDateForFind.id` as option. + const findModelData = await models[SPEC_MODEL_NAME].findOne({ + where: { + id: modelDateForFind.id + } + }); Object.keys(fakeData.findOne).forEach(e => { - expect(findModel[e]).to.equal(fakeData.findOne[e]); + expect(findModelData[e]).to.equal(fakeData.findOne[e]); }); }); }); @@ -111,31 +125,35 @@ describe(`models/${modelName}`, () => { describe('Find all model data', () => { before(async () => { // create 3 models and push into models array. - // await models[modelName].create(data1); - await models[modelName].bulkCreate(fakeData.findAll); + // await models[SPEC_MODEL_NAME].create(data1); + await models[SPEC_MODEL_NAME].bulkCreate(fakeData.findAll); }); it('find all model', async () => { // TODO: // 1. use model.findAll... // 2. use data from `fakeData.findAll` - // 3. use `findAllModel` as target. - let findAllModel = null; + // 3. use `findAllModelData` as target. + const findAllModelData = await models[SPEC_MODEL_NAME].findAll(); - expect(findAllModel.length).to.greaterThan(fakeData.findAll.length - 1); + expect(findAllModelData.length).to.greaterThan(fakeData.findAll.length - 1); }); it('find all with where', async () => { // TODO: // 1. use model.findAll... // 2. use data from `fakeData.findAll` - // 3. use `findAllModel` as target, and use `fakeData.keyword` as option. - let findAllModel = null; - - expect(findAllModel.length).to.greaterThan(fakeData.findAll.length - 1); - Object.keys(fakeData.findAll).forEach(e => { - expect(findAllModel[e]).to.equal(fakeData.findAll[e]); + // 3. use `findAllModelData` as target, and use `fakeData.keyword` as option. + const findAllModelData = await models[SPEC_MODEL_NAME].findAll({ + where: { + total: fakeData.keyword.total + } }); + + expect(findAllModelData.length).to.greaterThan(fakeData.findAll.length - 1); + for (const index in findAllModelData) { + expect(findAllModelData[index].total).to.equal(fakeData.findAll[0].total); + } }); }); @@ -143,18 +161,28 @@ describe(`models/${modelName}`, () => { let modelDataForDestroy = null; before(async () => { // create data before run test - modelDataForDestroy = await models[modelName].create(fakeData.destroy); + modelDataForDestroy = await models[SPEC_MODEL_NAME].create(fakeData.destroy); }); it('delete a model data with where', async () => { // TODO: // 1. use model.destroy... // 2. use data from `fakeData.findAll` - // 3. use `findAllModel` as target, and use `modelDataForDestroy.id` as option. - let deleteModel = null; - let findDeleteModel = null; - expect(deleteModel).to.equal(1); - expect(findDeleteModel).to.equal(null); + // 3. use `findAllModelData` as target, and use `modelDataForDestroy.id` as option. + const deleteModelData = await models[SPEC_MODEL_NAME].destroy({ + where: { + id: modelDataForDestroy.id + } + }); + + const findDeleteModelData = await models[SPEC_MODEL_NAME].findOne({ + where: { + id: modelDataForDestroy.id + } + }); + + expect(deleteModelData).to.equal(1); + expect(findDeleteModelData).to.equal(null); }); }); }); diff --git a/test/unit/models/passport.spec.js b/test/unit/models/passport.spec.js index cb092a4..88ec847 100644 --- a/test/unit/models/passport.spec.js +++ b/test/unit/models/passport.spec.js @@ -45,7 +45,7 @@ const fakeData = { }, }; -describe(`models/${modelName}`, () => { +describe.skip(`models/${modelName}`, () => { before(() => { }); diff --git a/test/unit/models/restaurant.spec.js b/test/unit/models/restaurant.spec.js index c0ea4b9..f50300f 100644 --- a/test/unit/models/restaurant.spec.js +++ b/test/unit/models/restaurant.spec.js @@ -45,7 +45,7 @@ const fakeData = { }, }; -describe(`models/${modelName}`, () => { +describe.skip(`models/${modelName}`, () => { before(() => { }); diff --git a/test/unit/models/user.spec.js b/test/unit/models/user.spec.js index 45b320e..fd22f26 100644 --- a/test/unit/models/user.spec.js +++ b/test/unit/models/user.spec.js @@ -53,7 +53,7 @@ const fakeData = { }, }; -describe(`models/${modelName}`, () => { +describe.skip(`models/${modelName}`, () => { before(() => { }); diff --git a/test/unit/models/userOrder.spec.js b/test/unit/models/userOrder.spec.js index dba0aaf..a7daa6f 100644 --- a/test/unit/models/userOrder.spec.js +++ b/test/unit/models/userOrder.spec.js @@ -45,7 +45,7 @@ const fakeData = { }, }; -describe(`models/${modelName}`, () => { +describe.skip(`models/${modelName}`, () => { before(() => { });