refactor: Use unauthorized user describe block for getUser tests

This commit is contained in:
Faruk AYDIN
2023-10-04 12:23:45 +02:00
parent 24c95f4801
commit ffb2f4f5db

View File

@@ -4,26 +4,28 @@ import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id'
import Crypto from 'crypto'; import Crypto from 'crypto';
describe('getUser', () => { describe('getUser', () => {
it('should throw not authorized error for an unauthorized user', async () => { describe('with unauthorized user', () => {
const invalidUserId = '123123123'; it('should throw not authorized error', async () => {
const invalidUserId = '123123123';
const query = ` const query = `
query { query {
getUser(id: "${invalidUserId}") { getUser(id: "${invalidUserId}") {
id id
email email
}
} }
} `;
`;
const response = await request(app) const response = await request(app)
.post('/graphql') .post('/graphql')
.set('Authorization', 'invalid-token') .set('Authorization', 'invalid-token')
.send({ query }) .send({ query })
.expect(200); .expect(200);
expect(response.body.errors).toBeDefined(); expect(response.body.errors).toBeDefined();
expect(response.body.errors[0].message).toEqual('Not Authorised!'); expect(response.body.errors[0].message).toEqual('Not Authorised!');
});
}); });
describe('with authorized user', () => { describe('with authorized user', () => {