forked from ovotech/bit-node-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.spec.ts
More file actions
33 lines (30 loc) · 1.2 KB
/
Copy pathmessage.spec.ts
File metadata and controls
33 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Schema, Type } from 'avsc';
import { constructMessage, deconstructMessage } from '../src';
const schemas: { [key: number]: Schema } = {
1: {
type: 'record',
name: 'TestSchema1',
fields: [{ name: 'accountId', type: 'string' }],
} as Schema,
2: {
type: 'record',
name: 'TestSchema2',
fields: [{ name: 'effectiveEnrollmentDate', type: { type: 'int', logicalType: 'date' } }],
} as Schema,
};
describe('AvroDeserializer test', () => {
it.each`
constructed | id | buffer
${new Buffer([0, 0, 0, 0, 1, 6, 49, 49, 49])} | ${1} | ${{ accountId: '111' }}
${new Buffer([0, 0, 0, 0, 1, 6, 50, 50, 50])} | ${1} | ${{ accountId: '222' }}
${new Buffer([0, 0, 0, 0, 2, 174, 148, 2])} | ${2} | ${{ effectiveEnrollmentDate: 17687 }}
${new Buffer([0, 0, 0, 0, 2, 190, 146, 2])} | ${2} | ${{ effectiveEnrollmentDate: 17567 }}
`('deconstructMessage', ({ constructed, id, buffer }) => {
const avroMessage = {
schemaId: id,
buffer: Type.forSchema(schemas[id]).toBuffer(buffer),
};
expect(deconstructMessage(constructed)).toEqual(avroMessage);
expect(constructMessage(avroMessage)).toEqual(constructed);
});
});