Skip to content

Commit 5ba66d3

Browse files
committed
Add emulator unit tests
1 parent ea4bd5f commit 5ba66d3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"lint": "run-p lint:src lint:test",
1616
"test": "run-s lint test:unit",
1717
"integration": "run-s build test:integration",
18-
"test:unit": "mocha test/unit/data-connect/*.spec.ts --require ts-node/register",
19-
"test:integration": "mocha test/integration/setup.ts test/integration/data-connect.spec.ts --slow 5000 --timeout 20000 --require ts-node/register",
18+
"test:unit": "mocha test/unit/*.spec.ts --require ts-node/register",
19+
"test:integration": "mocha test/integration/*.ts --slow 5000 --timeout 20000 --require ts-node/register",
2020
"test:coverage": "nyc npm run test:unit",
2121
"lint:src": "eslint src/ --ext .ts",
2222
"lint:test": "eslint test/ --ext .ts",

test/unit/data-connect/data-connect-api-client-internal.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ describe('DataConnectApiClient', () => {
8787

8888
afterEach(() => {
8989
sandbox.restore();
90+
if (process.env.DATA_CONNECT_EMULATOR_HOST) {
91+
delete process.env.DATA_CONNECT_EMULATOR_HOST;
92+
}
9093
return app.delete();
9194
});
9295

@@ -204,5 +207,21 @@ describe('DataConnectApiClient', () => {
204207
});
205208
});
206209
});
210+
211+
it('should use DATA_CONNECT_EMULATOR_HOST if set', () => {
212+
process.env.DATA_CONNECT_EMULATOR_HOST = 'http://localhost:9000';
213+
const stub = sandbox
214+
.stub(HttpClient.prototype, 'send')
215+
.resolves(utils.responseFrom(TEST_RESPONSE, 200));
216+
return apiClient.executeGraphql('query', {})
217+
.then(() => {
218+
expect(stub).to.have.been.calledOnce.and.calledWith({
219+
method: 'POST',
220+
url: `http://localhost:9000/v1alpha/projects/test-project/locations/${connectorConfig.location}/services/${connectorConfig.serviceId}:executeGraphql`,
221+
headers: EXPECTED_HEADERS,
222+
data: { query: 'query' }
223+
});
224+
});
225+
});
207226
});
208227
});

0 commit comments

Comments
 (0)