-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start unit test on serialization
- Loading branch information
Showing
5 changed files
with
95 additions
and
4 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
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,41 @@ | ||
|
||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import { serializeIdentifier } from './identifier.utils.js'; | ||
|
||
describe('serializeIdentifier', () => { | ||
|
||
it('serialize numeric id into buffer', () => { | ||
assert.deepEqual( | ||
serializeIdentifier(123).length, | ||
1 + 1 + 4 | ||
); | ||
}); | ||
|
||
it('serialize numeric string into buffer', () => { | ||
const strId = 'Groot'; | ||
assert.deepEqual( | ||
serializeIdentifier(strId).length, | ||
1 + 1 + strId.length | ||
); | ||
}); | ||
|
||
it('throw on empty string id', () => { | ||
assert.throws( | ||
() => serializeIdentifier(''), | ||
); | ||
}); | ||
|
||
it('throw on string id > 255 bytes', () => { | ||
assert.throws( | ||
() => serializeIdentifier('YoLo'.repeat(65)), | ||
); | ||
}); | ||
|
||
it('throw on login > 255 bytes - utf8 version', () => { | ||
assert.throws( | ||
() => serializeIdentifier('¥Ø£Ø'.repeat(33)), | ||
); | ||
}); | ||
|
||
}); |
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
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,49 @@ | ||
|
||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import { LOGIN } from './login.command.js'; | ||
|
||
describe("Login Command", () => { | ||
|
||
// @warn use ascii char to keep char.length === byteLength | ||
const login = 'iggyYolo'; | ||
const password = 'unitTestSeCret'; | ||
|
||
it("serialize credentials into a buffer", () => { | ||
assert.deepEqual( | ||
LOGIN.serialize(login, password).length, | ||
2 + login.length + password.length | ||
); | ||
}); | ||
|
||
it("throw on empty login", () => { | ||
assert.throws( | ||
() => LOGIN.serialize("", password) | ||
); | ||
}); | ||
|
||
it("throw on empty password", () => { | ||
assert.throws( | ||
() => LOGIN.serialize(login, "") | ||
); | ||
}); | ||
|
||
it("throw on login > 255 bytes", () => { | ||
assert.throws( | ||
() => LOGIN.serialize("YoLo".repeat(65), password) | ||
); | ||
}); | ||
|
||
it("throw on login > 255 bytes - utf8 version", () => { | ||
assert.throws( | ||
() => LOGIN.serialize("¥Ø£Ø".repeat(33), password) | ||
); | ||
}); | ||
|
||
it("throw on password > 255 bytes - utf8 version", () => { | ||
assert.throws( | ||
() => LOGIN.serialize(login, "¥Ø£Ø".repeat(33)) | ||
); | ||
}); | ||
|
||
}); |
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