cosmos-db-repositories
Version:
cosmos-db repositories
74 lines (73 loc) • 3.32 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const entity_utils_1 = __importDefault(require("./entity.utils"));
describe('entity Util', () => {
const sut = entity_utils_1.default;
it('cleanup', () => {
const entity = {
name: 'foo',
_rid: 'undefined',
_self: 'undefined',
_etag: 'undefined',
_attachments: 'undefined',
_ts: 'undefined'
};
const answer = sut.cleanUp(entity);
expect(answer).toBeDefined();
expect(answer).toEqual({ "name": "foo" });
});
it('create', () => {
const entity = { name: 'foo' };
const answer = sut.create(entity);
expect(answer).toBeDefined();
expect(answer.id).toBeDefined();
expect(answer.createdDate).toBeDefined();
expect(answer).toEqual({ "name": "foo", markAsDeleted: false, createdDate: answer.createdDate, id: answer.id });
});
it('create with meta as object', () => {
const entity = { name: 'foo' };
const answer = sut.create(entity, { meta: true });
expect(answer).toBeDefined();
expect(answer).toEqual({ "name": "foo", markAsDeleted: false, createdDate: answer.createdDate, meta: true, id: answer.id });
});
it('create with meta as function', () => {
const entity = { name: 'foo' };
const answer = sut.create(entity, (e) => ({ meta: true }));
expect(answer).toBeDefined();
expect(answer).toEqual({ "name": "foo", markAsDeleted: false, createdDate: answer.createdDate, meta: true, id: answer.id });
});
it('create with meta as function', () => {
const entity = { name: 'foo' };
const answer = sut.create(entity, (e) => ({ meta: e.name.toUpperCase() }));
expect(answer).toBeDefined();
expect(answer).toEqual({ "name": "foo", markAsDeleted: false, createdDate: answer.createdDate, meta: "FOO", id: answer.id });
});
it('update', () => {
const entity = { name: 'foo' };
const answer = sut.update(entity);
expect(answer).toBeDefined();
expect(answer.updatedDate).toBeDefined();
expect(answer).toEqual({ "name": "foo", updatedDate: answer.updatedDate, id: answer.id });
});
it('update with meta as object', () => {
const entity = { name: 'foo' };
const answer = sut.update(entity, { meta: true });
expect(answer).toBeDefined();
expect(answer).toEqual({ "name": "foo", updatedDate: answer.updatedDate, meta: true });
});
it('update with meta as function', () => {
const entity = { name: 'foo' };
const answer = sut.update(entity, (e) => ({ meta: true }));
expect(answer).toBeDefined();
expect(answer).toEqual({ "name": "foo", updatedDate: answer.updatedDate, meta: true });
});
it('update with meta as function', () => {
const entity = { name: 'foo' };
const answer = sut.update(entity, (e) => ({ meta: e.name.toUpperCase() }));
expect(answer).toBeDefined();
expect(answer).toEqual({ "name": "foo", updatedDate: answer.updatedDate, meta: "FOO" });
});
});