mirror of
https://github.com/appy-one/acebase.git
synced 2026-06-30 06:02:02 -06:00
51 lines
No EOL
2 KiB
JavaScript
51 lines
No EOL
2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const tempdb_1 = require("./tempdb");
|
|
describe('JSON data export', () => {
|
|
let db, removeDB;
|
|
beforeAll(async () => {
|
|
({ db, removeDB } = await (0, tempdb_1.createTempDB)());
|
|
});
|
|
it('should be typesafe', async () => {
|
|
const obj = {
|
|
name: 'Ewout',
|
|
country: 'The Netherlands',
|
|
points: 125,
|
|
created: new Date(),
|
|
};
|
|
await db.ref('object').set(obj);
|
|
let json = '';
|
|
await db.ref('object').export((str) => { json += str; }, { format: 'json', type_safe: true });
|
|
expect(typeof json).toBe('string');
|
|
let serialized;
|
|
expect(() => { serialized = JSON.parse(json); }).not.toThrow();
|
|
expect(typeof serialized).toBe('object');
|
|
expect(serialized.name).toEqual(obj.name);
|
|
expect(serialized.country).toEqual(obj.country);
|
|
expect(serialized.points).toEqual(obj.points);
|
|
expect(serialized.created).toEqual({ '.type': 'date', '.val': obj.created.toISOString() });
|
|
});
|
|
it('should allow not to be typesafe', async () => {
|
|
const obj = {
|
|
name: 'Ewout',
|
|
country: 'The Netherlands',
|
|
points: 125,
|
|
created: new Date(),
|
|
};
|
|
await db.ref('object2').set(obj);
|
|
let json = '';
|
|
await db.ref('object2').export((str) => { json += str; }, { format: 'json', type_safe: false });
|
|
expect(typeof json).toBe('string');
|
|
let serialized;
|
|
expect(() => { serialized = JSON.parse(json); }).not.toThrow();
|
|
expect(typeof serialized).toBe('object');
|
|
expect(serialized.name).toEqual(obj.name);
|
|
expect(serialized.country).toEqual(obj.country);
|
|
expect(serialized.points).toEqual(obj.points);
|
|
expect(serialized.created).toEqual(obj.created.toISOString());
|
|
});
|
|
afterAll(async () => {
|
|
await removeDB();
|
|
});
|
|
});
|
|
//# sourceMappingURL=json-data-export.spec.js.map
|