smartjson/test/test.both.ts

63 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

import { tap, expect } from '@pushrocks/tapbundle';
2017-02-27 13:05:03 +00:00
2022-06-09 17:54:43 +00:00
import * as smartjson from '../ts/index.js';
2017-02-27 13:05:03 +00:00
2022-06-09 17:54:43 +00:00
class SomeClass extends smartjson.Smartjson {
@smartjson.foldDec() thisis: string = 'test';
2018-07-23 22:38:54 +00:00
constructor() {
super();
console.log(this.saveableProperties);
2017-02-27 13:05:03 +00:00
}
}
2018-07-23 22:38:54 +00:00
let mySomeClass: SomeClass;
2017-02-27 13:05:03 +00:00
tap.test('should create a Foldable extended instance', async () => {
2018-07-23 22:38:54 +00:00
mySomeClass = new SomeClass();
2022-06-09 17:54:43 +00:00
expect(mySomeClass).toBeInstanceOf(SomeClass);
expect(mySomeClass).toBeInstanceOf(smartjson.Smartjson);
2018-07-23 22:38:54 +00:00
});
2017-02-27 13:05:03 +00:00
tap.test('should create a folded object', async () => {
2018-07-23 22:38:54 +00:00
let foldedObject = mySomeClass.foldToObject();
2022-06-09 17:54:43 +00:00
expect(foldedObject).property('thisis').toEqual('test');
2018-07-23 22:38:54 +00:00
});
2017-02-27 13:05:03 +00:00
tap.test('should enfold from object', async () => {
2020-10-05 11:13:17 +00:00
const mySomeClass2 = SomeClass.enfoldFromObject({ thisis: 'test2' });
2022-06-09 17:54:43 +00:00
expect(mySomeClass2).property('thisis').toEqual('test2');
});
tap.test('should products stable jsons', async () => {
const jsonString = smartjson.stringify({
a: 1,
f: 6,
b: 3,
c: 3,
e: 5,
d: 4,
});
console.log(jsonString);
2018-07-23 22:38:54 +00:00
});
2022-10-26 08:56:01 +00:00
tap.test('should work with base64', async () => {
2022-09-13 19:37:42 +00:00
const someObject = {
hi: 'there',
thisIs: 'awesome',
};
const base64Json = smartjson.stringifyBase64(someObject);
console.log(base64Json);
const decodedObject = smartjson.parseBase64(base64Json);
expect(decodedObject).toEqual(someObject);
2022-10-26 08:52:14 +00:00
});
tap.test('stringify should handle plain string', async () => {
const stringifiedString = smartjson.stringify('hello');
console.log(stringifiedString);
2022-10-26 08:56:01 +00:00
expect(stringifiedString).toEqual('"hello"');
2022-10-26 08:52:14 +00:00
expect(smartjson.parse(stringifiedString)).toEqual('hello');
2022-10-26 08:56:01 +00:00
});
2022-09-13 19:37:42 +00:00
tap.start();