generated from wednesday-solutions/nodejs-hapi-template
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathaddress.test.js
More file actions
65 lines (58 loc) · 1.89 KB
/
address.test.js
File metadata and controls
65 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const { closeRedisConnection } = require('@server/services/redis');
const { getMockDBEnv, getResponse } = require('@server/utils/testUtils');
const { get } = require('lodash');
const createAddressMutation = `
mutation {
createAddress(
latitude: 123.456,
longitude: -78.90,
address1: "123 Main St",
address2: "France",
city: "Sample City",
country: "Sample Country"
) {
id
address1
address2
city
country
latitude
longitude
createdAt
updatedAt
deletedAt
}
}
`;
describe('Integration test for createAddress mutation', () => {
const OLD_ENV = process.env;
beforeEach(() => {
jest.resetModules();
jest.unmock('@database');
jest.unmock('@database/models');
jest.unmock('ioredis');
process.env = { ...OLD_ENV };
process.env = { ...process.env, ...getMockDBEnv(), REDIS_PORT: 6380 };
});
afterAll(async () => {
process.env = OLD_ENV; // Restore old environment
await closeRedisConnection(); // avoid jest open handle error
});
it('should create an address', async () => {
const response = await getResponse(createAddressMutation);
// Assuming your mutation returns the created address
const createdAddress = get(response, 'body.data.createAddress');
// Perform assertions based on the response
expect(createdAddress).toBeTruthy();
expect(createdAddress.id).toBeTruthy();
expect(createdAddress.address1).toBe('123 Main St');
expect(createdAddress.address2).toBe('France');
expect(createdAddress.city).toBe('Sample City');
expect(createdAddress.country).toBe('Sample Country');
expect(createdAddress.latitude).toBe(123.456);
expect(createdAddress.longitude).toBe(-78.9);
expect(createdAddress.createdAt).toBeTruthy();
expect(createdAddress.updatedAt).toBeTruthy();
expect(createdAddress.deletedAt).toBeNull();
});
});