-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
stainless-bot
committed
Nov 20, 2024
1 parent
e6575de
commit 9907273
Showing
2 changed files
with
48 additions
and
1 deletion.
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,43 @@ | ||
import { toBase64 } from '@tryfinch/finch-api/core'; | ||
|
||
describe('toBase64', () => { | ||
const testCases = [ | ||
{ | ||
input: 'hello world', | ||
expected: 'aGVsbG8gd29ybGQ=', | ||
}, | ||
{ | ||
input: new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]), | ||
expected: 'aGVsbG8gd29ybGQ=', | ||
}, | ||
{ | ||
input: undefined, | ||
expected: '', | ||
}, | ||
]; | ||
describe('with Buffer', () => { | ||
test('it converts to base64', async () => { | ||
testCases.forEach(({ input, expected }) => { | ||
expect(toBase64(input)).toBe(expected); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('without buffer', () => { | ||
let originalBuffer: BufferConstructor; | ||
beforeAll(() => { | ||
originalBuffer = globalThis.Buffer; | ||
// @ts-expect-error Can't assign undefined to BufferConstructor | ||
globalThis.Buffer = undefined; | ||
}); | ||
afterAll(() => { | ||
globalThis.Buffer = originalBuffer; | ||
}); | ||
|
||
test('it converts to base64', async () => { | ||
testCases.forEach(({ input, expected }) => { | ||
expect(toBase64(input)).toBe(expected); | ||
}); | ||
}); | ||
}); | ||
}); |