-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathdataplaneClient.spec.ts
More file actions
96 lines (81 loc) · 3.4 KB
/
Copy pathdataplaneClient.spec.ts
File metadata and controls
96 lines (81 loc) · 3.4 KB
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
import { expect } from "chai";
import nock from "../test/helpers/nock";
import * as chai from "chai";
import {
dataconnectDataplaneClient,
executeGraphQL,
executeGraphQLRead,
executeGraphQLQuery,
executeGraphQLMutation,
} from "./dataplaneClient";
import * as types from "./types";
chai.use(require("chai-as-promised"));
describe("dataplaneClient", () => {
const servicePath = "projects/my-project/locations/us-central1/services/my-service";
const connectorPath = `${servicePath}/connectors/my-connector`;
afterEach(() => {
nock.cleanAll();
});
describe("executeGraphQL", () => {
it("should make a POST request to the executeGraphql endpoint", async () => {
const requestBody: types.ExecuteGraphqlRequest = {
query: "query { users { id } }",
};
const expectedResponse = { data: { users: [{ id: "1" }] } };
nock("https://firebasedataconnect.googleapis.com")
.post(`/v1/${servicePath}:executeGraphql`, (body) => body.query === requestBody.query)
.reply(200, expectedResponse);
const client = dataconnectDataplaneClient();
const response = await executeGraphQL(client, servicePath, requestBody);
expect(response.body).to.deep.equal(expectedResponse);
});
});
describe("executeGraphQLRead", () => {
it("should make a POST request to the executeGraphqlRead endpoint", async () => {
const requestBody: types.ExecuteGraphqlRequest = {
query: "query { users { id } }",
};
const expectedResponse = { data: { users: [{ id: "1" }] } };
nock("https://firebasedataconnect.googleapis.com")
.post(`/v1/${servicePath}:executeGraphqlRead`, (body) => body.query === requestBody.query)
.reply(200, expectedResponse);
const client = dataconnectDataplaneClient();
const response = await executeGraphQLRead(client, servicePath, requestBody);
expect(response.body).to.deep.equal(expectedResponse);
});
});
describe("executeGraphQLQuery", () => {
it("should make a POST request to the executeQuery endpoint", async () => {
const requestBody: types.ExecuteOperationRequest = {
operationName: "getUsers",
};
const expectedResponse = { data: { users: [{ id: "1" }] } };
nock("https://firebasedataconnect.googleapis.com")
.post(
`/v1/${connectorPath}:executeQuery`,
(body) => body.operationName === requestBody.operationName,
)
.reply(200, expectedResponse);
const client = dataconnectDataplaneClient();
const response = await executeGraphQLQuery(client, connectorPath, requestBody);
expect(response.body).to.deep.equal(expectedResponse);
});
});
describe("executeGraphQLMutation", () => {
it("should make a POST request to the executeMutation endpoint", async () => {
const requestBody: types.ExecuteOperationRequest = {
operationName: "createUser",
};
const expectedResponse = { data: { createUser: { id: "1" } } };
nock("https://firebasedataconnect.googleapis.com")
.post(
`/v1/${connectorPath}:executeMutation`,
(body) => body.operationName === requestBody.operationName,
)
.reply(200, expectedResponse);
const client = dataconnectDataplaneClient();
const response = await executeGraphQLMutation(client, connectorPath, requestBody);
expect(response.body).to.deep.equal(expectedResponse);
});
});
});