Skip to content

Commit cb7c3f6

Browse files
Add tests
1 parent e8cc49f commit cb7c3f6

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/utils/convertToArray.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import convertToArray from './convertToArray';
2+
3+
describe('convertToArray()', () => {
4+
it('Should return arrays as is', () => {
5+
const result = convertToArray([1, 2, 3]);
6+
expect(result).toStrictEqual([1, 2, 3]);
7+
});
8+
9+
it('Should convert strings to arrays of chars', () => {
10+
const result = convertToArray('hello');
11+
expect(result).toStrictEqual(['h', 'e', 'l', 'l', 'o']);
12+
});
13+
14+
it('Should convert Buffers to arrays of ints', () => {
15+
const result = convertToArray(Uint8Array.from([1, 5, 12]).buffer);
16+
expect(result).toStrictEqual([1, 5 , 12]);
17+
});
18+
});

src/utils/getResultsFromArrayBuffer.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ export interface Options {
2929
returnRawBuffers?: boolean;
3030
}
3131

32-
type Result = string[] | string | number[] | bigint[] | number[][] | bigint[][];
32+
type Result =
33+
| string[]
34+
| string
35+
| number[]
36+
| bigint[]
37+
| number[][]
38+
| bigint[][]
39+
| ArrayBufferLike[];
3340

3441
/**
3542
* Convert an ArrayBuffer to a map of attributes with their results
@@ -133,9 +140,13 @@ export const getResultsFromArrayBuffer = async (
133140
? concatChars(groupedValues as string[][])
134141
: (groupedValues as number[][] | bigint[][]);
135142

136-
// Fix: Type
143+
/**
144+
* ParallelJS accepts data that are JSON serializable
145+
* thus we have to convert buffer to array of uint8
146+
* and after grouping convert the data back to ArrayBuffer.
147+
*/
137148
if (selectedAttributeSchema.type === Datatype.Blob) {
138-
const arrayBuffers: any = groupedValues.map(
149+
const arrayBuffers = groupedValues.map(
139150
ints => Uint8Array.from(ints).buffer
140151
);
141152
result = arrayBuffers;

0 commit comments

Comments
 (0)