Skip to content

Commit 9c0c871

Browse files
committed
chore: pr feedback
1 parent 153bfcb commit 9c0c871

File tree

1 file changed

+14
-48
lines changed

1 file changed

+14
-48
lines changed

packages/common/src/codecs/primitives/bytes-base64.spec.ts

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('BytesBase64Codec', () => {
2727
})
2828
})
2929

30-
describe('JSON format', () => {
30+
describe('non default values', () => {
3131
test.each<{ bytes: number[]; expectedBase64: string; description: string }>([
3232
{ bytes: [72, 101, 108, 108, 111], expectedBase64: 'SGVsbG8=', description: '"Hello" in ASCII' },
3333
{ bytes: [0, 1, 2, 3, 4], expectedBase64: 'AAECAwQ=', description: 'small byte sequence' },
@@ -41,30 +41,13 @@ describe('BytesBase64Codec', () => {
4141
},
4242
])('should encode $description as base64 string', ({ bytes, expectedBase64 }) => {
4343
const uint8Array = new Uint8Array(bytes)
44-
const encoded = bytesBase64Codec.encode(uint8Array, 'json')
45-
expect(encoded).toBe(expectedBase64)
46-
expect(typeof encoded).toBe('string')
47-
})
48-
})
44+
const encodedJson = bytesBase64Codec.encode(uint8Array, 'json')
45+
const encodedMsgpack = bytesBase64Codec.encode(uint8Array, 'msgpack')
4946

50-
describe('msgpack format', () => {
51-
test.each<{ bytes: number[]; expectedBase64: string; description: string }>([
52-
{ bytes: [72, 101, 108, 108, 111], expectedBase64: 'SGVsbG8=', description: '"Hello" in ASCII' },
53-
{ bytes: [0, 1, 2, 3, 4], expectedBase64: 'AAECAwQ=', description: 'small byte sequence' },
54-
{ bytes: [255, 254, 253, 252], expectedBase64: '//79/A==', description: 'high byte values' },
55-
{ bytes: [0], expectedBase64: 'AA==', description: 'single zero byte' },
56-
{ bytes: [255], expectedBase64: '/w==', description: 'single max byte' },
57-
{
58-
bytes: Array.from({ length: 100 }, (_, i) => i % 256),
59-
expectedBase64:
60-
'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiYw==',
61-
description: '100-byte sequence',
62-
},
63-
])('should encode $description as base64 string (not pass-through)', ({ bytes, expectedBase64 }) => {
64-
const uint8Array = new Uint8Array(bytes)
65-
const encoded = bytesBase64Codec.encode(uint8Array, 'msgpack')
66-
expect(typeof encoded).toBe('string')
67-
expect(encoded).toBe(expectedBase64)
47+
expect(typeof encodedJson).toBe('string')
48+
expect(encodedJson).toBe(expectedBase64)
49+
expect(typeof encodedMsgpack).toBe('string')
50+
expect(encodedMsgpack).toBe(expectedBase64)
6851
})
6952
})
7053
})
@@ -81,7 +64,7 @@ describe('BytesBase64Codec', () => {
8164
})
8265
})
8366

84-
describe('JSON format', () => {
67+
describe('non default values', () => {
8568
test.each<{ bytes: number[]; expectedBase64: string; description: string }>([
8669
{ bytes: [72, 101, 108, 108, 111], expectedBase64: 'SGVsbG8=', description: '"Hello" in ASCII' },
8770
{ bytes: [0, 1, 2, 3, 4], expectedBase64: 'AAECAwQ=', description: 'small byte sequence' },
@@ -95,30 +78,13 @@ describe('BytesBase64Codec', () => {
9578
},
9679
])('should encode $description as base64 string', ({ bytes, expectedBase64 }) => {
9780
const uint8Array = new Uint8Array(bytes)
98-
const encoded = bytesBase64Codec.encodeOptional(uint8Array, 'json')
99-
expect(encoded).toBe(expectedBase64)
100-
expect(typeof encoded).toBe('string')
101-
})
102-
})
81+
const encodedJson = bytesBase64Codec.encodeOptional(uint8Array, 'json')
82+
const encodedMsgpack = bytesBase64Codec.encodeOptional(uint8Array, 'msgpack')
10383

104-
describe('msgpack format', () => {
105-
test.each<{ bytes: number[]; expectedBase64: string; description: string }>([
106-
{ bytes: [72, 101, 108, 108, 111], expectedBase64: 'SGVsbG8=', description: '"Hello" in ASCII' },
107-
{ bytes: [0, 1, 2, 3, 4], expectedBase64: 'AAECAwQ=', description: 'small byte sequence' },
108-
{ bytes: [255, 254, 253, 252], expectedBase64: '//79/A==', description: 'high byte values' },
109-
{ bytes: [0], expectedBase64: 'AA==', description: 'single zero byte' },
110-
{ bytes: [255], expectedBase64: '/w==', description: 'single max byte' },
111-
{
112-
bytes: Array.from({ length: 100 }, (_, i) => i % 256),
113-
expectedBase64:
114-
'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiYw==',
115-
description: '100-byte sequence',
116-
},
117-
])('should encode $description as base64 string (not pass-through)', ({ bytes, expectedBase64 }) => {
118-
const uint8Array = new Uint8Array(bytes)
119-
const encoded = bytesBase64Codec.encodeOptional(uint8Array, 'msgpack')
120-
expect(typeof encoded).toBe('string')
121-
expect(encoded).toBe(expectedBase64)
84+
expect(typeof encodedJson).toBe('string')
85+
expect(encodedJson).toBe(expectedBase64)
86+
expect(typeof encodedMsgpack).toBe('string')
87+
expect(encodedMsgpack).toBe(expectedBase64)
12288
})
12389
})
12490
})

0 commit comments

Comments
 (0)