Skip to content

Commit cc03960

Browse files
committed
Added test IDs
1 parent 699a700 commit cc03960

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
mutation RemovePost($id: UUID!) @auth(level: PUBLIC) {
22
post_delete(id: $id)
33
}
4-
mutation AddPost($id: UUID!, $description: String!) @auth(level: PUBLIC) {
4+
mutation AddPost($id: UUID!, $description: String!, $testId: String!) @auth(level: PUBLIC) {
55
post_insert(data: {
66
id: $id,
7-
description: $description
7+
description: $description,
8+
testId: $testId
89
})
910
}

packages/data-connect/test/dataconnect/connector/queries.gql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
query ListPosts @auth(level: PUBLIC) {
2-
posts {
1+
query ListPosts($testId: String!) @auth(level: PUBLIC) {
2+
posts(where: {
3+
testId: {
4+
eq: $testId
5+
}
6+
}) {
37
id,
4-
description
8+
description,
59
}
610
}
711

packages/data-connect/test/dataconnect/schema/schema.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
# }
1717
type Post @table {
1818
description: String!
19+
testId: String!
1920
}

packages/data-connect/test/queries.test.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,46 @@ async function deleteDatabase(instance: DataConnect): Promise<void> {
7070
await executeMutation(ref);
7171
}
7272
}
73-
async function seedDatabase(instance: DataConnect): Promise<void> {
73+
async function seedDatabase(
74+
instance: DataConnect,
75+
testId: string
76+
): Promise<void> {
7477
for (let i = 0; i < SEEDED_DATA.length; i++) {
75-
const data = SEEDED_DATA[i];
78+
const data = { ...SEEDED_DATA[i], testId };
7679
const ref = mutationRef(instance, 'AddPost', data);
7780
await executeMutation(ref);
7881
}
7982
}
8083

84+
interface PostVariables {
85+
testId: string;
86+
}
8187
describe('DataConnect Tests', async () => {
8288
let dc: DataConnect;
89+
const TEST_ID = crypto.randomUUID();
8390
beforeEach(async () => {
8491
dc = initDatabase();
85-
await seedDatabase(dc);
92+
await seedDatabase(dc, TEST_ID);
8693
});
8794
afterEach(async () => {
8895
await deleteDatabase(dc);
8996
await terminate(dc);
9097
});
98+
function getPostsRef(): QueryRef<PostListResponse, PostVariables> {
99+
return queryRef<PostListResponse, PostVariables>(dc, 'ListPosts', {
100+
testId: TEST_ID
101+
});
102+
}
91103
it('Can get all posts', async () => {
92-
const taskListQuery = queryRef<PostListResponse>(dc, 'ListPosts');
104+
const taskListQuery = getPostsRef();
93105
const taskListRes = await executeQuery(taskListQuery);
94106
expect(taskListRes.data).to.deep.eq({
95107
posts: REAL_DATA
96108
});
97109
});
98110
it(`instantly executes a query if one hasn't been subscribed to`, async () => {
99-
const taskListQuery = queryRef<PostListResponse>(dc, 'ListPosts');
100-
const promise = new Promise<QueryResult<PostListResponse, undefined>>(
111+
const taskListQuery = getPostsRef();
112+
const promise = new Promise<QueryResult<PostListResponse, PostVariables>>(
101113
(resolve, reject) => {
102114
const unsubscribe = subscribe(taskListQuery, {
103115
onNext: res => {
@@ -118,17 +130,17 @@ describe('DataConnect Tests', async () => {
118130
expect(res.source).to.eq(SOURCE_SERVER);
119131
});
120132
it(`returns the result source as cache when data already exists`, async () => {
121-
const taskListQuery = queryRef<PostListResponse>(dc, 'ListPosts');
133+
const taskListQuery = getPostsRef();
122134
const queryResult = await executeQuery(taskListQuery);
123135
const result = await waitForFirstEvent(taskListQuery);
124136
expect(result.data).to.eq(queryResult.data);
125137
expect(result.source).to.eq(SOURCE_CACHE);
126138
});
127139
it(`returns the proper JSON when calling .toJSON()`, async () => {
128-
const taskListQuery = queryRef<PostListResponse>(dc, 'ListPosts');
140+
const taskListQuery = getPostsRef();
129141
await executeQuery(taskListQuery);
130142
const result = await waitForFirstEvent(taskListQuery);
131-
const serializedRef: SerializedRef<PostListResponse, undefined> = {
143+
const serializedRef: SerializedRef<PostListResponse, PostVariables> = {
132144
data: {
133145
posts: REAL_DATA
134146
},
@@ -139,7 +151,7 @@ describe('DataConnect Tests', async () => {
139151
projectId: PROJECT_ID
140152
},
141153
name: taskListQuery.name,
142-
variables: undefined
154+
variables: { testId: TEST_ID }
143155
},
144156
source: SOURCE_CACHE
145157
};

0 commit comments

Comments
 (0)