Skip to content

Commit 9a78752

Browse files
committed
Adding in unit test for the X-Aleo-SDK-Version header
1 parent 6a7b7b9 commit 9a78752

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: sdk/tests/network-client.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ jest.retryTimes(3);
66

77
describe('NodeConnection', () => {
88
let connection: AleoNetworkClient;
9+
let windowFetchSpy: jest.Spied<typeof fetch>;
910

1011
beforeEach(() => {
1112
connection = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
13+
windowFetchSpy = jest.spyOn(globalThis, 'fetch');
14+
});
15+
16+
afterEach(() => {
17+
jest.restoreAllMocks();
18+
windowFetchSpy = null;
1219
});
1320

1421
describe('setAccount', () => {
@@ -76,6 +83,25 @@ describe('NodeConnection', () => {
7683
const latestBlock = await connection.getLatestBlock();
7784
expect(typeof (latestBlock as Block).block_hash).toBe('string');
7885
}, 60000);
86+
87+
it('should set the X-Aleo-SDK-Version header', async () => {
88+
expect(windowFetchSpy.mock.calls).toStrictEqual([]);
89+
90+
await connection.getLatestBlock();
91+
92+
expect(windowFetchSpy.mock.calls).toStrictEqual([
93+
[
94+
"https://api.explorer.aleo.org/v1/testnet3/latest/block",
95+
{
96+
"headers": {
97+
// @TODO: Run the Jest tests on the compiled Rollup code,
98+
// so that way the version is properly replaced.
99+
"X-Aleo-SDK-Version": "%%VERSION%%"
100+
}
101+
}
102+
],
103+
]);
104+
}, 60000);
79105
});
80106

81107
describe('getLatestCommittee', () => {

0 commit comments

Comments
 (0)