-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify selectHighestCompatibleVersion
- Loading branch information
1 parent
9665bc1
commit 13a8a0b
Showing
2 changed files
with
5 additions
and
114 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 |
---|---|---|
|
@@ -56,85 +56,3 @@ describe("NWCClient", () => { | |
expect(nwcClient.options.lud16).toBe("[email protected]"); | ||
}); | ||
}); | ||
|
||
describe("selectHighestCompatibleVersion", () => { | ||
let nwcClient: NWCClient; | ||
let selectVersion: (walletVersions: string[]) => string | null; | ||
const ORIGINAL_SUPPORTED_VERSIONS = NWCClient.SUPPORTED_VERSIONS; | ||
|
||
beforeEach(() => { | ||
nwcClient = new NWCClient(); | ||
// Access the private method using type assertion | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
selectVersion = (nwcClient as any).selectHighestCompatibleVersion; | ||
}); | ||
|
||
afterEach(() => { | ||
// Restore the original SUPPORTED_VERSIONS | ||
NWCClient.SUPPORTED_VERSIONS = [...ORIGINAL_SUPPORTED_VERSIONS]; | ||
}); | ||
|
||
test("both client and wallet support version 1.0", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0", "1.0"]; | ||
const walletVersions = ["0.0", "1.0"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBe("1.0"); | ||
}); | ||
|
||
test("client supports version 1.0 but wallet does not", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0", "1.0"]; | ||
const walletVersions = ["0.0"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBe("0.0"); | ||
}); | ||
|
||
test("wallet supports version 1.0 but client does not", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0"]; | ||
const walletVersions = ["0.0", "1.0"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBe("0.0"); | ||
}); | ||
|
||
test("wallet and client do not have overlapping versions", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0"]; | ||
const walletVersions = ["1.0"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBeNull(); | ||
}); | ||
|
||
// Tests for future | ||
test("client supports more versions than wallet", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0", "1.3"]; | ||
const walletVersions = ["1.2"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBe("1.2"); | ||
}); | ||
|
||
test("wallet supports more versions than client", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0", "1.4"]; | ||
const walletVersions = ["1.6"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBe("1.4"); | ||
}); | ||
|
||
test("wallet and client have no overlapping major versions", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0", "1.0"]; | ||
const walletVersions = ["2.0"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBeNull(); | ||
}); | ||
|
||
test("both client and wallet support multiple versions with different majors", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0", "1.0", "2.4"]; | ||
const walletVersions = ["1.0", "2.3"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBe("2.3"); | ||
}); | ||
|
||
test("wallet has duplicate versions", () => { | ||
NWCClient.SUPPORTED_VERSIONS = ["0.0", "1.2"]; | ||
const walletVersions = ["1.1", "1.1"]; | ||
const selected = selectVersion(walletVersions); | ||
expect(selected).toBe("1.1"); | ||
}); | ||
}); |
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