refactor: Use shared requestObject for getUser tests

This commit is contained in:
Faruk AYDIN
2023-10-04 18:38:47 +02:00
parent a29b3c6db4
commit b290c32aeb

View File

@@ -32,7 +32,11 @@ describe('getUser', () => {
}); });
describe('with authorized user', () => { describe('with authorized user', () => {
let role: any, currentUser: any, anotherUser: any, token: any; let role: any,
currentUser: any,
anotherUser: any,
token: any,
requestObject: any;
beforeEach(async () => { beforeEach(async () => {
role = await createRole({ role = await createRole({
@@ -55,6 +59,9 @@ describe('getUser', () => {
}); });
token = createAuthTokenByUserId(currentUser.id); token = createAuthTokenByUserId(currentUser.id);
requestObject = request(app)
.post('/graphql')
.set('Authorization', `${token}`);
}); });
it('should return user data for a valid user id', async () => { it('should return user data for a valid user id', async () => {
@@ -75,11 +82,7 @@ describe('getUser', () => {
} }
`; `;
const response = await request(app) const response = await requestObject.send({ query }).expect(200);
.post('/graphql')
.set('Authorization', `${token}`)
.send({ query })
.expect(200);
const expectedResponsePayload = { const expectedResponsePayload = {
data: { data: {
@@ -117,11 +120,7 @@ describe('getUser', () => {
} }
`; `;
const response = await request(app) const response = await requestObject.send({ query }).expect(200);
.post('/graphql')
.set('Authorization', `${token}`)
.send({ query })
.expect(200);
expect(response.body.errors).toBeDefined(); expect(response.body.errors).toBeDefined();
expect(response.body.errors[0].message).toEqual('NotFoundError'); expect(response.body.errors[0].message).toEqual('NotFoundError');