forked from vendure-ecommerce/vendure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zone.e2e-spec.ts
200 lines (170 loc) · 6.13 KB
/
zone.e2e-spec.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import gql from 'graphql-tag';
import path from 'path';
import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
import { ZONE_FRAGMENT } from './graphql/fragments';
import {
AddMembersToZone,
CreateZone, DeleteZone,
DeletionResult,
GetCountryList,
GetZone, GetZones,
RemoveMembersFromZone,
UpdateZone,
} from './graphql/generated-e2e-admin-types';
import { GET_COUNTRY_LIST } from './graphql/shared-definitions';
import { TestAdminClient } from './test-client';
import { TestServer } from './test-server';
// tslint:disable:no-non-null-assertion
describe('Facet resolver', () => {
const client = new TestAdminClient();
const server = new TestServer();
let countries: GetCountryList.Items[];
let zones: Array<{ id: string; name: string }>;
let oceania: { id: string; name: string };
let pangaea: { id: string; name: string; members: any[] };
beforeAll(async () => {
await server.init({
productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
customerCount: 1,
});
await client.init();
const result = await client.query<GetCountryList.Query>(GET_COUNTRY_LIST, {});
countries = result.countries.items;
}, TEST_SETUP_TIMEOUT_MS);
afterAll(async () => {
await server.destroy();
});
it('zones', async () => {
const result = await client.query<GetZones.Query>(GET_ZONE_LIST);
expect(result.zones.length).toBe(5);
zones = result.zones;
oceania = zones[0];
});
it('zone', async () => {
const result = await client.query<GetZone.Query, GetZone.Variables>(GET_ZONE, {
id: oceania.id,
});
expect(result.zone!.name).toBe('Oceania');
});
it('updateZone', async () => {
const result = await client.query<UpdateZone.Mutation, UpdateZone.Variables>(UPDATE_ZONE, {
input: {
id: oceania.id,
name: 'oceania2',
},
});
expect(result.updateZone.name).toBe('oceania2');
});
it('createZone', async () => {
const result = await client.query<CreateZone.Mutation, CreateZone.Variables>(CREATE_ZONE, {
input: {
name: 'Pangaea',
memberIds: [countries[0].id, countries[1].id],
},
});
pangaea = result.createZone;
expect(pangaea.name).toBe('Pangaea');
expect(pangaea.members.map(m => m.name)).toEqual([countries[0].name, countries[1].name]);
});
it('addMembersToZone', async () => {
const result = await client.query<AddMembersToZone.Mutation, AddMembersToZone.Variables>(
ADD_MEMBERS_TO_ZONE,
{
zoneId: oceania.id,
memberIds: [countries[2].id, countries[3].id],
},
);
expect(!!result.addMembersToZone.members.find(m => m.name === countries[2].name)).toBe(true);
expect(!!result.addMembersToZone.members.find(m => m.name === countries[3].name)).toBe(true);
});
it('removeMembersFromZone', async () => {
const result = await client.query<RemoveMembersFromZone.Mutation, RemoveMembersFromZone.Variables>(
REMOVE_MEMBERS_FROM_ZONE,
{
zoneId: oceania.id,
memberIds: [countries[0].id, countries[2].id],
},
);
expect(!!result.removeMembersFromZone.members.find(m => m.name === countries[0].name)).toBe(false);
expect(!!result.removeMembersFromZone.members.find(m => m.name === countries[2].name)).toBe(false);
expect(!!result.removeMembersFromZone.members.find(m => m.name === countries[3].name)).toBe(true);
});
describe('deletion', () => {
it('deletes Zone not used in any TaxRate', async () => {
const result1 = await client.query<DeleteZone.Mutation, DeleteZone.Variables>(DELETE_ZONE, { id: pangaea.id });
expect(result1.deleteZone).toEqual({
result: DeletionResult.DELETED,
message: '',
});
const result2 = await client.query<GetZones.Query>(GET_ZONE_LIST);
expect(result2.zones.find(c => c.id === pangaea.id)).toBeUndefined();
});
it('does not delete Zone that is used in one or more TaxRates', async () => {
const result1 = await client.query<DeleteZone.Mutation, DeleteZone.Variables>(DELETE_ZONE, { id: oceania.id });
expect(result1.deleteZone).toEqual({
result: DeletionResult.NOT_DELETED,
message:
'The selected Zone cannot be deleted as it is used in the following ' +
'TaxRates: Standard Tax Oceania, Reduced Tax Oceania, Zero Tax Oceania',
});
const result2 = await client.query<GetZones.Query>(GET_ZONE_LIST);
expect(result2.zones.find(c => c.id === oceania.id)).not.toBeUndefined();
});
});
});
const DELETE_ZONE = gql`
mutation DeleteZone($id: ID!) {
deleteZone(id: $id) {
result
message
}
}
`;
const GET_ZONE_LIST = gql`
query GetZones {
zones {
id
name
}
}
`;
export const GET_ZONE = gql`
query GetZone($id: ID!) {
zone(id: $id) {
...Zone
}
}
${ZONE_FRAGMENT}
`;
export const CREATE_ZONE = gql`
mutation CreateZone($input: CreateZoneInput!) {
createZone(input: $input) {
...Zone
}
}
${ZONE_FRAGMENT}
`;
export const UPDATE_ZONE = gql`
mutation UpdateZone($input: UpdateZoneInput!) {
updateZone(input: $input) {
...Zone
}
}
${ZONE_FRAGMENT}
`;
export const ADD_MEMBERS_TO_ZONE = gql`
mutation AddMembersToZone($zoneId: ID!, $memberIds: [ID!]!) {
addMembersToZone(zoneId: $zoneId, memberIds: $memberIds) {
...Zone
}
}
${ZONE_FRAGMENT}
`;
export const REMOVE_MEMBERS_FROM_ZONE = gql`
mutation RemoveMembersFromZone($zoneId: ID!, $memberIds: [ID!]!) {
removeMembersFromZone(zoneId: $zoneId, memberIds: $memberIds) {
...Zone
}
}
${ZONE_FRAGMENT}
`;