UNPKG

typ3s

Version:
63 lines 3.67 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable no-template-curly-in-string */ const __1 = require(".."); let data; beforeAll(() => __awaiter(void 0, void 0, void 0, function* () { data = { id: 139, customerId: 'FAMIA', employeeId: 9, orderDate: '1996-12-17T23:00:00.000Z', requiredDate: '1996-12-31T23:00:00.000Z', shippedDate: '1996-12-24T23:00:00.000Z', shipViaId: 3, freight: 13.99, name: 'Familia Arquibaldo', address: 'Rua Ors, 92', city: 'Sao Paulo', region: 'SP', postalCode: '05442-030', country: 'Brazil', details: [ { orderId: 139, productId: 24, unitPrice: 3.6, quantity: 15, discount: 0 }, { orderId: 139, productId: 34, unitPrice: 11.2, quantity: 10, discount: 0 } ] }; })); describe('order', () => { test('serialize', () => { const type = __1.Type.type(data); const result = __1.Type.serialize(type); const expected = '{"primitive":"obj","obj":{"properties":[{"name":"id","type":{"primitive":"integer"}},{"name":"customerId","type":{"primitive":"string"}},{"name":"employeeId","type":{"primitive":"integer"}},{"name":"orderDate","type":{"primitive":"string"}},{"name":"requiredDate","type":{"primitive":"string"}},{"name":"shippedDate","type":{"primitive":"string"}},{"name":"shipViaId","type":{"primitive":"integer"}},{"name":"freight","type":{"primitive":"decimal"}},{"name":"name","type":{"primitive":"string"}},{"name":"address","type":{"primitive":"string"}},{"name":"city","type":{"primitive":"string"}},{"name":"region","type":{"primitive":"string"}},{"name":"postalCode","type":{"primitive":"string"}},{"name":"country","type":{"primitive":"string"}},{"name":"details","type":{"primitive":"list","list":{"items":{"primitive":"obj","obj":{"properties":[{"name":"orderId","type":{"primitive":"integer"}},{"name":"productId","type":{"primitive":"integer"}},{"name":"unitPrice","type":{"primitive":"decimal"}},{"name":"quantity","type":{"primitive":"integer"}},{"name":"discount","type":{"primitive":"integer"}}]}}}}}]}}'; expect(expected).toStrictEqual(result); }); test('stringify', () => { const type = __1.Type.type(data); const result = __1.Type.stringify(type); const expected = '{id:integer,customerId:string,employeeId:integer,orderDate:string,requiredDate:string,shippedDate:string,shipViaId:integer,freight:decimal,name:string,address:string,city:string,region:string,postalCode:string,country:string,details:[{orderId:integer,productId:integer,unitPrice:decimal,quantity:integer,discount:integer}]}'; expect(expected).toStrictEqual(result); }); }); //# sourceMappingURL=order.test.js.map