Skip to content

Commit 127faf5

Browse files
committed
Add integration test
1 parent e51db9e commit 127faf5

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

src/__tests__/areas.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { ApolloServer } from 'apollo-server'
22
import muuid from 'uuid-mongodb'
33
import { jest } from '@jest/globals'
44
import MutableAreaDataSource, { createInstance as createAreaInstance } from '../model/MutableAreaDataSource.js'
5+
import { createInstance as createClimbInstance } from '../model/MutableClimbDataSource.js'
56
import MutableOrganizationDataSource, { createInstance as createOrgInstance } from '../model/MutableOrganizationDataSource.js'
67
import { AreaType } from '../db/AreaTypes.js'
8+
import { ClimbChangeInputType } from '../db/ClimbTypes.js'
79
import { OrgType, OrganizationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes.js'
810
import { queryAPI, setUpServer } from '../utils/testUtils.js'
911
import { muuidToString } from '../utils/helpers.js'
@@ -22,6 +24,7 @@ describe('areas API', () => {
2224
let usa: AreaType
2325
let ca: AreaType
2426
let wa: AreaType
27+
let ak: AreaType
2528

2629
beforeAll(async () => {
2730
({ server, inMemoryDB } = await setUpServer())
@@ -38,13 +41,65 @@ describe('areas API', () => {
3841
usa = await areas.addCountry('usa')
3942
ca = await areas.addArea(user, 'CA', usa.metadata.area_id)
4043
wa = await areas.addArea(user, 'WA', usa.metadata.area_id)
44+
ak = await areas.addArea(user, 'AK', usa.metadata.area_id)
4145
})
4246

4347
afterAll(async () => {
4448
await server.stop()
4549
await inMemoryDB.close()
4650
})
4751

52+
describe('mutations', () => {
53+
it('updates sorting order of subareas and queries returns them in order', async () => {
54+
const updateSortingOrderQuery = `
55+
mutation ($input: [AreaSortingInput]) {
56+
updateAreasSortingOrder(input: $input)
57+
}
58+
`
59+
const updateResponse = await queryAPI({
60+
query: updateSortingOrderQuery,
61+
variables: {
62+
input: [
63+
{ areaId: wa.metadata.area_id, leftRightIndex: 3 },
64+
{ areaId: ca.metadata.area_id, leftRightIndex: 0 },
65+
{ areaId: ak.metadata.area_id, leftRightIndex: 10 }
66+
]
67+
},
68+
userUuid
69+
})
70+
71+
expect(updateResponse.statusCode).toBe(200)
72+
const sortingOrderResult = updateResponse.body.data.updateAreasSortingOrder
73+
expect(sortingOrderResult).toHaveLength(3)
74+
75+
const areaChildrenQuery = `
76+
query area($input: ID) {
77+
area(uuid: $input) {
78+
children {
79+
uuid
80+
metadata {
81+
leftRightIndex
82+
}
83+
}
84+
}
85+
}
86+
`
87+
88+
const areaChildrenResponse = await queryAPI({
89+
query: areaChildrenQuery,
90+
variables: { input: usa.metadata.area_id },
91+
userUuid
92+
})
93+
94+
expect(areaChildrenResponse.statusCode).toBe(200)
95+
const areaResult = areaChildrenResponse.body.data.area
96+
// In leftRightIndex order
97+
expect(areaResult.children[0]).toMatchObject({ uuid: muuidToString(ca.metadata.area_id), metadata: { leftRightIndex: 0 } })
98+
expect(areaResult.children[1]).toMatchObject({ uuid: muuidToString(wa.metadata.area_id), metadata: { leftRightIndex: 3 } })
99+
expect(areaResult.children[2]).toMatchObject({ uuid: muuidToString(ak.metadata.area_id), metadata: { leftRightIndex: 10 } })
100+
})
101+
})
102+
48103
describe('queries', () => {
49104
const areaQuery = `
50105
query area($input: ID) {
@@ -101,5 +156,56 @@ describe('areas API', () => {
101156
// ca and so should not be listed.
102157
expect(areaResult.organizations).toHaveLength(0)
103158
})
159+
160+
it('returns climbs in leftRightIndex order', async () => {
161+
const climbs = createClimbInstance()
162+
const leftRoute: ClimbChangeInputType = {
163+
name: 'left',
164+
disciplines: { sport: true },
165+
description: 'Leftmost route on the wall',
166+
leftRightIndex: 0
167+
}
168+
const middleRoute: ClimbChangeInputType = {
169+
name: 'middle',
170+
disciplines: { sport: true },
171+
description: 'Middle route on the wall',
172+
leftRightIndex: 1
173+
}
174+
const rightRoute: ClimbChangeInputType = {
175+
name: 'right',
176+
disciplines: { sport: true },
177+
description: 'Rightmost route on the wall',
178+
leftRightIndex: 2
179+
}
180+
await climbs.addOrUpdateClimbs(
181+
user,
182+
ca.metadata.area_id,
183+
[middleRoute, leftRoute, rightRoute]
184+
)
185+
186+
const areaClimbsQuery = `
187+
query area($input: ID) {
188+
area(uuid: $input) {
189+
climbs {
190+
name
191+
metadata {
192+
leftRightIndex
193+
}
194+
}
195+
}
196+
}
197+
`
198+
const areaClimbsResponse = await queryAPI({
199+
query: areaClimbsQuery,
200+
variables: { input: ca.metadata.area_id },
201+
userUuid
202+
})
203+
expect(areaClimbsResponse.statusCode).toBe(200)
204+
const areaResult = areaClimbsResponse.body.data.area
205+
// In leftRightIndex order
206+
expect(areaResult.climbs[0]).toMatchObject({ name: 'left', metadata: { leftRightIndex: 0 } })
207+
expect(areaResult.climbs[1]).toMatchObject({ name: 'middle', metadata: { leftRightIndex: 1 } })
208+
expect(areaResult.climbs[2]).toMatchObject({ name: 'right', metadata: { leftRightIndex: 2 } })
209+
})
104210
})
105211
})

0 commit comments

Comments
 (0)