This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(network): add unit tests for Network util functions
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { describe, expect, it } from 'bun:test' | ||
import { NetworkId } from 'src/network/constants' | ||
import { isAlgodConfig, isNetworkConfigMap, isValidNetworkId } from 'src/network/utils' | ||
|
||
describe('Type Guards', () => { | ||
describe('isValidNetworkId', () => { | ||
it('returns true for a valid NetworkId', () => { | ||
expect(isValidNetworkId(NetworkId.TESTNET)).toBe(true) | ||
}) | ||
|
||
it('returns false for an invalid NetworkId', () => { | ||
expect(isValidNetworkId('foo')).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('isAlgodConfig', () => { | ||
it('returns true for a valid AlgodConfig', () => { | ||
expect( | ||
isAlgodConfig({ | ||
token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', | ||
baseServer: 'http://localhost', | ||
port: 1234, | ||
headers: { | ||
'X-Foo': 'bar' | ||
} | ||
}) | ||
).toBe(true) | ||
|
||
expect( | ||
isAlgodConfig({ | ||
token: '', | ||
baseServer: '' | ||
}) | ||
).toBe(true) | ||
}) | ||
|
||
it('returns false for an invalid AlgodConfig', () => { | ||
expect( | ||
isAlgodConfig({ | ||
baseServer: '' | ||
}) | ||
).toBe(false) | ||
|
||
expect( | ||
isAlgodConfig({ | ||
token: '' | ||
}) | ||
).toBe(false) | ||
|
||
expect( | ||
isAlgodConfig({ | ||
token: '', | ||
baseServer: '', | ||
foo: '' | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('isNetworkConfigMap', () => { | ||
it('returns true for a valid NetworkConfigMap', () => { | ||
const validConfigMap = { | ||
[NetworkId.MAINNET]: { | ||
token: '', | ||
baseServer: '' | ||
}, | ||
[NetworkId.TESTNET]: { | ||
token: '', | ||
baseServer: '' | ||
} | ||
} | ||
expect(isNetworkConfigMap(validConfigMap)).toBe(true) | ||
}) | ||
|
||
it('returns false for an invalid NetworkConfigMap', () => { | ||
expect( | ||
isNetworkConfigMap({ | ||
token: '', | ||
baseServer: '' | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters