From 6f9096c09a5283f69e557038176bffe9878e6eb4 Mon Sep 17 00:00:00 2001 From: Hajar RAHMOUNI Date: Sun, 19 Nov 2023 20:59:05 +0100 Subject: [PATCH] token passed in header --- test/ad.test.js | 54 +++++++++++++++++++++++++---------------------- test/user.test.js | 4 ++-- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/test/ad.test.js b/test/ad.test.js index 3610760..df71582 100644 --- a/test/ad.test.js +++ b/test/ad.test.js @@ -359,39 +359,41 @@ describe('Ad Routes', () => { describe('Query graphQl : getAds and getAd By Id', () => { it('should return a list of ads', async () => { const query = ` - query { - getAds(token: "${agent1AuthToken}") { - _id - title - propertyType - publicationStatus - propertyStatus - description - price - availabilityDate - photos - userName - questions { - user - question - } + query { + getAds { + _id + title + propertyType + publicationStatus + propertyStatus + description + price + availabilityDate + photos + userName + questions { + user + question } } - `; + } + `; - const response = await chai - .request(app) - .post('/graphql') - .send({ query }); + const response = await chai + .request(app) + .post('/graphql') + .set('Authorization', `Bearer ${agent1AuthToken}`) + .send({ query }); - expect(response).to.have.status(200); - expect(response.body).to.have.property('data'); - expect(response.body.data).to.have.property('getAds'); + expect(response).to.have.status(200); + expect(response.body).to.have.property('data'); + expect(response.body.data).to.have.property('getAds'); }); + it('should return details of a specific ad', async () => { const query = ` query { - getAdById(adId: "${adId}", token: "${agent2AuthToken}") { + getAdById(adId: "${adId}") { _id title propertyType @@ -413,6 +415,7 @@ describe('Ad Routes', () => { const response = await chai .request(app) .post('/graphql') + .set('Authorization', `Bearer ${agent2AuthToken}`) .send({ query }); expect(response).to.have.status(200); @@ -421,6 +424,7 @@ describe('Ad Routes', () => { }); }); + describe('Mutation: addAd', () => { it('Adds a new ad and returns the correct fields', async () => { const variables = { diff --git a/test/user.test.js b/test/user.test.js index 2926239..8fe9dac 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -8,7 +8,7 @@ const mongoose = require('mongoose'); chai.use(chaiHttp); let testUserToken; -/*describe('Authentication Routes', () => { +describe('Authentication Routes', () => { describe('POST /user', () => { it('should create a new user', (done) => { chai @@ -84,4 +84,4 @@ let testUserToken; await mongoose.connection.close(); } }); -});*/ +}); -- GitLab