Skip to content

Commit ff0e245

Browse files
test: Update the tests for postgresql and mysql
1 parent 066732f commit ff0e245

File tree

2 files changed

+138
-32
lines changed

2 files changed

+138
-32
lines changed

examples/fetch-all-with-negative/e2e/todo-cursor-fetch-all-enable.resolver.spec.ts

Lines changed: 82 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { cursorPageInfoField, edgeNodes, todoItemFields } from './graphql-fragme
1212
describe('TodoItemResolver (cursor pagination - fetch all with negative enabled)', () => {
1313
let app: INestApplication
1414

15+
const describeIf = (condition: boolean) => (condition ? describe : describe.skip)
16+
1517
beforeAll(async () => {
1618
const moduleRef = await Test.createTestingModule({
1719
imports: [AppModule]
@@ -36,14 +38,14 @@ describe('TodoItemResolver (cursor pagination - fetch all with negative enabled)
3638

3739
describe('query', () => {
3840
describe('paging', () => {
39-
it('should return all the nodes after the given cursor', () =>
41+
it('should return all the nodes', () =>
4042
request(app.getHttpServer())
4143
.post('/graphql')
4244
.send({
4345
operationName: null,
4446
variables: {},
4547
query: `{
46-
todoItemCursorFetchWithNegativeEnables(paging: {first: -1, after: "YXJyYXljb25uZWN0aW9uOjE="}) {
48+
todoItemCursorFetchWithNegativeEnables(paging: {first: -1}) {
4749
${cursorPageInfoField}
4850
${edgeNodes(todoItemFields)}
4951
}
@@ -56,41 +58,94 @@ describe('TodoItemResolver (cursor pagination - fetch all with negative enabled)
5658
expect(pageInfo).toEqual({
5759
endCursor: 'YXJyYXljb25uZWN0aW9uOjk5',
5860
hasNextPage: false,
59-
hasPreviousPage: true,
60-
startCursor: 'YXJyYXljb25uZWN0aW9uOjI='
61+
hasPreviousPage: false,
62+
startCursor: 'YXJyYXljb25uZWN0aW9uOjA='
6163
})
62-
expect(edges).toHaveLength(98)
64+
expect(edges).toHaveLength(100)
6365

64-
expect(edges.map((e) => e.node)).toEqual(todoItems.slice(2))
66+
expect(edges.map((e) => e.node)).toEqual(todoItems)
6567
}))
66-
it('should return all the nodes before the given cursor', () =>
67-
request(app.getHttpServer())
68-
.post('/graphql')
69-
.send({
70-
operationName: null,
71-
variables: {},
72-
query: `{
68+
69+
describeIf(process.env.NESTJS_QUERY_DB_TYPE == 'postgres')('postgres', () => {
70+
it('should return all the nodes after the given cursor', () =>
71+
request(app.getHttpServer())
72+
.post('/graphql')
73+
.send({
74+
operationName: null,
75+
variables: {},
76+
query: `{
77+
todoItemCursorFetchWithNegativeEnables(paging: {first: -1, after: "YXJyYXljb25uZWN0aW9uOjE="}) {
78+
${cursorPageInfoField}
79+
${edgeNodes(todoItemFields)}
80+
}
81+
}`
82+
})
83+
.expect(200)
84+
.then(({ body }) => {
85+
const { edges, pageInfo }: CursorConnectionType<TodoItemCursorFetchWithNegativeEnableDTO> =
86+
body.data.todoItemCursorFetchWithNegativeEnables
87+
expect(pageInfo).toEqual({
88+
endCursor: 'YXJyYXljb25uZWN0aW9uOjk5',
89+
hasNextPage: false,
90+
hasPreviousPage: true,
91+
startCursor: 'YXJyYXljb25uZWN0aW9uOjI='
92+
})
93+
expect(edges).toHaveLength(98)
94+
95+
expect(edges.map((e) => e.node)).toEqual(todoItems.slice(2))
96+
}))
97+
})
98+
99+
describeIf(process.env.NESTJS_QUERY_DB_TYPE == 'mysql')('mysql', () => {
100+
it('should return an error when requesting all the nodes after the given cursor', () =>
101+
request(app.getHttpServer())
102+
.post('/graphql')
103+
.send({
104+
operationName: null,
105+
variables: {},
106+
query: `{
107+
todoItemCursorFetchWithNegativeEnables(paging: {first: -1, after: "YXJyYXljb25uZWN0aW9uOjE="}) {
108+
${cursorPageInfoField}
109+
${edgeNodes(todoItemFields)}
110+
}
111+
}`
112+
})
113+
.expect(200)
114+
.then(({ body }) => {
115+
expect(body.errors).toBeDefined()
116+
expect(body.errors).toHaveLength(1)
117+
expect(body.errors[0].message).toContain('RDBMS does not support OFFSET without LIMIT in SELECT statements')
118+
expect(body.data).toBeNull()
119+
}))
120+
})
121+
})
122+
it('should return an error when request all the nodes before the given cursor', () =>
123+
request(app.getHttpServer())
124+
.post('/graphql')
125+
.send({
126+
operationName: null,
127+
variables: {},
128+
query: `{
73129
todoItemCursorFetchWithNegativeEnables(paging: {last: -1, before: "YXJyYXljb25uZWN0aW9uOjk4"}) {
74130
${cursorPageInfoField}
75131
${edgeNodes(todoItemFields)}
76132
}
77133
}`
134+
})
135+
.expect(200)
136+
.then(({ body }) => {
137+
const { edges, pageInfo }: CursorConnectionType<TodoItemCursorFetchWithNegativeEnableDTO> =
138+
body.data.todoItemCursorFetchWithNegativeEnables
139+
expect(pageInfo).toEqual({
140+
endCursor: 'YXJyYXljb25uZWN0aW9uOjk3',
141+
hasNextPage: true,
142+
hasPreviousPage: false,
143+
startCursor: 'YXJyYXljb25uZWN0aW9uOjA='
78144
})
79-
.expect(200)
80-
.then(({ body }) => {
81-
const { edges, pageInfo }: CursorConnectionType<TodoItemCursorFetchWithNegativeEnableDTO> =
82-
body.data.todoItemCursorFetchWithNegativeEnables
83-
expect(pageInfo).toEqual({
84-
endCursor: 'YXJyYXljb25uZWN0aW9uOjk3',
85-
hasNextPage: true,
86-
hasPreviousPage: false,
87-
startCursor: 'YXJyYXljb25uZWN0aW9uOjA='
88-
})
89-
expect(edges).toHaveLength(98)
145+
expect(edges).toHaveLength(98)
90146

91-
expect(edges.map((e) => e.node)).toEqual(todoItems.slice(0, 98))
92-
}))
93-
})
147+
expect(edges.map((e) => e.node)).toEqual(todoItems.slice(0, 98))
148+
}))
94149
})
95150

96151
afterAll(async () => {

examples/fetch-all-with-negative/e2e/todo-offset-fetch-all-enable.resolver.spec.ts

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { nodes as graphqlNodes, offsetPageInfoField, todoItemFields } from './gr
1212
describe('TodoItemResolver (offset pagination - fetch all with negative enabled)', () => {
1313
let app: INestApplication
1414

15+
const describeIf = (condition: boolean) => (condition ? describe : describe.skip)
16+
1517
beforeAll(async () => {
1618
const moduleRef = await Test.createTestingModule({
1719
imports: [AppModule]
@@ -36,14 +38,14 @@ describe('TodoItemResolver (offset pagination - fetch all with negative enabled)
3638

3739
describe('query', () => {
3840
describe('paging', () => {
39-
it('should return all the nodes after the given offset', () =>
41+
it('should return all the nodes', () =>
4042
request(app.getHttpServer())
4143
.post('/graphql')
4244
.send({
4345
operationName: null,
4446
variables: {},
4547
query: `{
46-
todoItemOffsetFetchWithNegativeEnables(paging: {limit: -1, offset: 2}) {
48+
todoItemOffsetFetchWithNegativeEnables(paging: {limit: -1}) {
4749
${offsetPageInfoField}
4850
${graphqlNodes(todoItemFields)}
4951
}
@@ -55,12 +57,61 @@ describe('TodoItemResolver (offset pagination - fetch all with negative enabled)
5557
body.data.todoItemOffsetFetchWithNegativeEnables
5658
expect(pageInfo).toEqual({
5759
hasNextPage: false,
58-
hasPreviousPage: true
60+
hasPreviousPage: false
5961
})
60-
expect(nodes).toHaveLength(98)
62+
expect(nodes).toHaveLength(100)
6163

62-
expect(nodes).toEqual(todoItems.slice(2))
64+
expect(nodes).toEqual(todoItems)
6365
}))
66+
describeIf(process.env.NESTJS_QUERY_DB_TYPE == 'postgres')('postgres', () => {
67+
it('should return all the nodes after the given offset', () =>
68+
request(app.getHttpServer())
69+
.post('/graphql')
70+
.send({
71+
operationName: null,
72+
variables: {},
73+
query: `{
74+
todoItemOffsetFetchWithNegativeEnables(paging: {limit: -1, offset: 2}) {
75+
${offsetPageInfoField}
76+
${graphqlNodes(todoItemFields)}
77+
}
78+
}`
79+
})
80+
.expect(200)
81+
.then(({ body }) => {
82+
const { nodes, pageInfo }: OffsetConnectionType<TodoItemOffsetFetchWithNegativeEnableDTO> =
83+
body.data.todoItemOffsetFetchWithNegativeEnables
84+
expect(pageInfo).toEqual({
85+
hasNextPage: false,
86+
hasPreviousPage: true
87+
})
88+
expect(nodes).toHaveLength(98)
89+
90+
expect(nodes).toEqual(todoItems.slice(2))
91+
}))
92+
})
93+
describeIf(process.env.NESTJS_QUERY_DB_TYPE == 'mysql')('mysql', () => {
94+
it('should return an error when fetching all the nodes after the given offset', () =>
95+
request(app.getHttpServer())
96+
.post('/graphql')
97+
.send({
98+
operationName: null,
99+
variables: {},
100+
query: `{
101+
todoItemOffsetFetchWithNegativeEnables(paging: {limit: -1, offset: 2}) {
102+
${offsetPageInfoField}
103+
${graphqlNodes(todoItemFields)}
104+
}
105+
}`
106+
})
107+
.expect(200)
108+
.then(({ body }) => {
109+
expect(body.errors).toBeDefined()
110+
expect(body.errors).toHaveLength(1)
111+
expect(body.errors[0].message).toContain('RDBMS does not support OFFSET without LIMIT in SELECT statements')
112+
expect(body.data).toBeNull()
113+
}))
114+
})
64115
})
65116
})
66117

0 commit comments

Comments
 (0)