Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkmin committed Aug 6, 2024
1 parent fd8e900 commit 0e269bc
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/encoding/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
uint8ArrayFromHexString,
uint8ArrayToHexString,
base64StringToBase64UrlEncodedString,
base64urlToBuffer,
bufferToBase64url,
} from "..";

// Test for stringToBase64urlString
Expand Down Expand Up @@ -34,6 +36,34 @@ test("stringToBase64urlString", async function () {
);
});

test("base64urlToBuffer", async function () {
// Trivial test string
expect(base64urlToBuffer("aGVsbG8")).toEqual(
new Uint8Array([104, 101, 108, 108, 111])
); // "hello"

// Hello, World!
expect(base64urlToBuffer("SGVsbG8sIFdvcmxkIQ")).toEqual(
new Uint8Array([72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33])
);
});

test("bufferToBase64url", async function () {
// Trivial test string
expect(bufferToBase64url(new Uint8Array([104, 101, 108, 108, 111]))).toEqual(
"aGVsbG8"
); // "hello"

// Hello, World!
expect(
bufferToBase64url(
new Uint8Array([
72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33,
])
)
).toEqual("SGVsbG8sIFdvcmxkIQ");
});

// Test for base64StringToBase64UrlEncodedString
test("base64StringToBase64UrlEncodedString", async function () {
// "hello world" => "aGVsbG8gd29ybGQ"
Expand Down

0 comments on commit 0e269bc

Please sign in to comment.