Skip to content

Commit 39dfb37

Browse files
committed
refactor(test): no mock server
1 parent f1fd315 commit 39dfb37

File tree

1 file changed

+52
-56
lines changed

1 file changed

+52
-56
lines changed

src/layers/5_client/client.customScalar.test.ts

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,67 @@ import { describe, expect } from 'vitest'
33
import { db } from '../../../tests/_/db.js'
44
import { createResponse, test } from '../../../tests/_/helpers.js'
55
import { Graffle } from '../../../tests/_/schema/generated/__.js'
6-
import { setupMockServer } from '../../../tests/legacy/__helpers.js'
76

8-
const ctx = setupMockServer()
97
const date0Encoded = db.date0.toISOString()
10-
const date1Encoded = db.date1.toISOString()
118

12-
const client = () => Graffle.create({ schema: ctx.url })
9+
const client = Graffle.create({ schema: 'https://foo' })
1310

14-
describe(`output`, () => {
15-
test(`query field`, async ({ fetch }) => {
16-
fetch.mockResolvedValueOnce(createResponse({ data: { date: date0Encoded } }))
17-
expect(await client().query.$batch({ date: true })).toEqual({ date: db.date0 })
18-
})
19-
test(`query field in non-null`, async ({ fetch }) => {
20-
fetch.mockResolvedValueOnce(createResponse({ data: { dateNonNull: date0Encoded } }))
21-
expect(await client().query.$batch({ dateNonNull: true })).toEqual({ dateNonNull: db.date0 })
11+
test(`query field`, async ({ fetch }) => {
12+
fetch.mockResolvedValueOnce(createResponse({ data: { date: date0Encoded } }))
13+
expect(await client.query.$batch({ date: true })).toEqual({ date: db.date0 })
14+
})
15+
test(`query field in non-null`, async ({ fetch }) => {
16+
fetch.mockResolvedValueOnce(createResponse({ data: { dateNonNull: date0Encoded } }))
17+
expect(await client.query.$batch({ dateNonNull: true })).toEqual({ dateNonNull: db.date0 })
18+
})
19+
test(`query field in list`, async ({ fetch }) => {
20+
fetch.mockResolvedValueOnce(createResponse({ data: { dateList: [0, 1] } }))
21+
expect(await client.query.$batch({ dateList: true })).toEqual({ dateList: [db.date0, new Date(1)] })
22+
})
23+
test(`query field in list non-null`, async ({ fetch }) => {
24+
fetch.mockResolvedValueOnce(createResponse({ data: { dateList: [0, 1] } }))
25+
expect(await client.query.$batch({ dateList: true })).toEqual({ dateList: [db.date0, new Date(1)] })
26+
})
27+
test(`object field`, async ({ fetch }) => {
28+
fetch.mockResolvedValueOnce(createResponse({ data: { dateObject1: { date1: 0 } } }))
29+
expect(await client.query.$batch({ dateObject1: { date1: true } })).toEqual({
30+
dateObject1: { date1: db.date0 },
2231
})
23-
test(`query field in list`, async ({ fetch }) => {
24-
fetch.mockResolvedValueOnce(createResponse({ data: { dateList: [0, 1] } }))
25-
expect(await client().query.$batch({ dateList: true })).toEqual({ dateList: [db.date0, new Date(1)] })
32+
})
33+
test(`object field in interface`, async ({ fetch }) => {
34+
fetch.mockResolvedValueOnce(createResponse({ data: { dateInterface1: { date1: 0 } } }))
35+
expect(await client.query.$batch({ dateInterface1: { date1: true } })).toEqual({
36+
dateInterface1: { date1: db.date0 },
2637
})
27-
test(`query field in list non-null`, async ({ fetch }) => {
28-
fetch.mockResolvedValueOnce(createResponse({ data: { dateList: [0, 1] } }))
29-
expect(await client().query.$batch({ dateList: true })).toEqual({ dateList: [db.date0, new Date(1)] })
38+
})
39+
40+
describe(`object field in union`, () => {
41+
test(`case 1 with __typename`, async ({ fetch }) => {
42+
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: { __typename: `DateObject1`, date1: 0 } } }))
43+
expect(await client.query.$batch({ dateUnion: { __typename: true, onDateObject1: { date1: true } } }))
44+
.toEqual({
45+
dateUnion: { __typename: `DateObject1`, date1: db.date0 },
46+
})
3047
})
31-
test(`object field`, async ({ fetch }) => {
32-
fetch.mockResolvedValueOnce(createResponse({ data: { dateObject1: { date1: 0 } } }))
33-
expect(await client().query.$batch({ dateObject1: { date1: true } })).toEqual({
34-
dateObject1: { date1: db.date0 },
48+
test(`case 1 without __typename`, async ({ fetch }) => {
49+
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: { date1: date0Encoded } } }))
50+
expect(await client.query.$batch({ dateUnion: { onDateObject1: { date1: true } } })).toEqual({
51+
dateUnion: { date1: db.date0 },
3552
})
3653
})
37-
test(`object field in interface`, async ({ fetch }) => {
38-
fetch.mockResolvedValueOnce(createResponse({ data: { dateInterface1: { date1: 0 } } }))
39-
expect(await client().query.$batch({ dateInterface1: { date1: true } })).toEqual({
40-
dateInterface1: { date1: db.date0 },
41-
})
54+
test(`case 2`, async ({ fetch }) => {
55+
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: { date2: date0Encoded } } }))
56+
expect(
57+
await client.query.$batch({
58+
dateUnion: { onDateObject1: { date1: true }, onDateObject2: { date2: true } },
59+
}),
60+
)
61+
.toEqual({ dateUnion: { date2: db.date0 } })
4262
})
43-
describe(`object field in union`, () => {
44-
test(`case 1 with __typename`, async ({ fetch }) => {
45-
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: { __typename: `DateObject1`, date1: 0 } } }))
46-
expect(await client().query.$batch({ dateUnion: { __typename: true, onDateObject1: { date1: true } } }))
47-
.toEqual({
48-
dateUnion: { __typename: `DateObject1`, date1: db.date0 },
49-
})
50-
})
51-
test(`case 1 without __typename`, async ({ fetch }) => {
52-
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: { date1: date0Encoded } } }))
53-
expect(await client().query.$batch({ dateUnion: { onDateObject1: { date1: true } } })).toEqual({
54-
dateUnion: { date1: db.date0 },
55-
})
56-
})
57-
test(`case 2`, async ({ fetch }) => {
58-
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: { date2: date0Encoded } } }))
59-
expect(
60-
await client().query.$batch({
61-
dateUnion: { onDateObject1: { date1: true }, onDateObject2: { date2: true } },
62-
}),
63-
)
64-
.toEqual({ dateUnion: { date2: db.date0 } })
65-
})
66-
test(`case 2 miss`, async ({ fetch }) => {
67-
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: null } }))
68-
expect(await client().query.$batch({ dateUnion: { onDateObject1: { date1: true } } })).toEqual({
69-
dateUnion: null,
70-
}) // dprint-ignore
71-
})
63+
test(`case 2 miss`, async ({ fetch }) => {
64+
fetch.mockResolvedValueOnce(createResponse({ data: { dateUnion: null } }))
65+
expect(await client.query.$batch({ dateUnion: { onDateObject1: { date1: true } } })).toEqual({
66+
dateUnion: null,
67+
}) // dprint-ignore
7268
})
7369
})

0 commit comments

Comments
 (0)