diff --git a/test/subjects/exercise.test.js b/test/subjects/exercise.test.js index f6f7630ca99169429b28a911daddd230531dd543..84d3554bcf96b915c2dd366c1663390339cdeec4 100644 --- a/test/subjects/exercise.test.js +++ b/test/subjects/exercise.test.js @@ -7,8 +7,9 @@ const { expect } = chai; chai.use(chaiHttp); function test() { - // let testExercise; + let testExercise; let testTrainee; + let testTraineeCookies; it('Add trainee', (done) => { request(app) @@ -30,6 +31,21 @@ function test() { done(); }); }); + it('Trainee Login', (done) => { + request(app) + .post('/auth/login/trainee') + .send({ + email: 'testforexercise@gmail.com', + password: 'passw0rd', + }) + .end((err, res) => { + expect(res).to.have.status(201); + + testTraineeCookies = res.header['set-cookie']; + done(); + }); + }); + // fetch all Exercise it('fetch all exercise', (done) => { @@ -43,28 +59,23 @@ function test() { }); // Add Exercise - /* TODO: Fix add exercise test. it('Add exercise', (done) => { request(app) .post('/exercise') + .set('Cookie', testTraineeCookies[1]) .send({ - memo: '�덈━�대룞', - feedback: '�덈━�쇨린', - traineeId: testTrainee.id, + exercise: '�덈━�대룞', }) .end((err, res) => { expect(res).to.have.status(201); - res.body.memo.should.be.a.String().and.exactly('�덈━�대룞'); - res.body.feedback.should.be.a.String().and.exactly('�덈━�쇨린'); + res.body.exercise.should.be.a.String().and.exactly('�덈━�대룞'); res.body.traineeId.should.be.a.Number().and.exactly(testTrainee.id); testExercise = res.body; done(); }); }); - */ // Get Exercise By Id - /* TODO: Fix get exercise by id test. it('Get Exercise By ID', (done) => { request(app) .get(`/exercise/${testExercise.id}`) @@ -74,67 +85,67 @@ function test() { done(); }); }); - */ + + // Add Exercise which is Forbidden Request + it('Add exercise which is Forbidden Request', (done) => { + request(app) + .post('/exercise') + .send({}) + .end((err, res) => { + expect(res).to.have.status(401); + done(); + }); + }); // Add Exercise which is Bad Request - /* TODO: Fix add exercise which is bad request test. it('Add exercise which is Bad Request', (done) => { request(app) .post('/exercise') - .send({ - memo: '�ㅻ━ 洹쇱쑁�� 醫뗭� �대룞', - feedback: '�ㅻ━�� �섏쓣 二쇨퀬 �ㅼ떆�� 寃�', - }) + .set('Cookie', testTraineeCookies[1]) + .send({}) .end((err, res) => { expect(res).to.have.status(400); done(); }); }); - */ // UPDATE Exercise - /* TODO: Fix update exercise test. it('Update exercise', (done) => { request(app) .put(`/exercise/${testExercise.id}`) + .set('Cookie', testTraineeCookies[1]) .send({ - memo: '紐� �대룞', feedback: '紐⑹뿉 留롮� �섏쓣 二쇰㈃ �덈맖', - traineeId: testTrainee.id, }) .end((err, res) => { expect(res).to.have.status(200); - res.body.exercise.memo.should.be.a.String().and.exactly('紐� �대룞'); res.body.exercise.feedback.should.be.a.String().and.exactly('紐⑹뿉 留롮� �섏쓣 二쇰㈃ �덈맖'); res.body.exercise.traineeId.should.be.a.Number().and.exactly(testTrainee.id); done(); }); }); - */ // DELETE Exercise - /* TODO: Fix delete exercise test. it('Delete exercise', (done) => { request(app) .delete(`/exercise/${testExercise.id}`) + .set('Cookie', testTraineeCookies[1]) .end((err, res) => { expect(res).to.have.status(204); done(); }); }); - */ // DELETE UnKnown Exercise - /* TODO: Fix delete unknown exercise test. it('Delete UnKnown exercise', (done) => { request(app) .delete(`/exercise/${testExercise.id}`) + .set('Cookie', testTraineeCookies[1]) .end((err, res) => { expect(res).to.have.status(404); done(); }); }); - */ // DELETE Trainee it('Delete trainee', (done) => {