Skip to content

Commit 3ace105

Browse files
committed
test: add unit test verifying the whoami endpoint will be called only once per process
1 parent c317abe commit 3ace105

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/services/ip-service.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,25 @@ describe("ipService", () => {
135135
assert.isTrue(logger.traceOutput.indexOf(errMsgForMyipCom) !== -1, `Trace output\n'${logger.traceOutput}'\ndoes not contain expected message:\n${errMsgForMyipCom}`);
136136
assert.isTrue(logger.traceOutput.indexOf(errMsgForIpifyOrg) !== -1, `Trace output\n'${logger.traceOutput}'\ndoes not contain expected message:\n${errMsgForMyipCom}`);
137137
});
138+
139+
it("is called only once per process", async () => {
140+
const testInjector = createTestInjector();
141+
const httpClient = testInjector.resolve<Server.IHttpClient>("httpClient");
142+
let httpRequestCounter = 0;
143+
httpClient.httpRequest = async (options: any, proxySettings?: IProxySettings): Promise<Server.IResponse> => {
144+
httpRequestCounter++;
145+
return <any>{ body: JSON.stringify({ ip }) };
146+
};
147+
148+
const ipService = testInjector.resolve<IIPService>("ipService");
149+
150+
const ipAddress = await ipService.getCurrentIPv4Address();
151+
assert.equal(httpRequestCounter, 1);
152+
assert.equal(ipAddress, ip);
153+
154+
const ipAddress2 = await ipService.getCurrentIPv4Address();
155+
assert.equal(httpRequestCounter, 1);
156+
assert.equal(ipAddress2, ip);
157+
});
138158
});
139159
});

0 commit comments

Comments
 (0)