+116
@@ -0,0 +1,116 @@
|
||||
import { describe, expect, it, jest } from "@jest/globals";
|
||||
import { CreateResult } from "../../../../../../../src/core/platform/framework/api/crud-service";
|
||||
import { RealtimeCreated } from "../../../../../../../src/core/platform/framework/decorators";
|
||||
import { websocketEventBus } from "../../../../../../../src/core/platform/services/realtime/bus";
|
||||
import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types";
|
||||
|
||||
describe("The RealtimeCreated decorator", () => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeCreated({ room: "/foo/bar" })
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
reverseMeBaby(input: string): Promise<string> {
|
||||
return Promise.resolve(input.split("").reverse().join(""));
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(0);
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
|
||||
it("should call the original method send back original result and emit event", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeCreated({ room: "/foo/bar", path: "/foo/bar/baz" })
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
async reverseMeBaby(input: string): Promise<CreateResult<string>> {
|
||||
return new CreateResult<string>("string", input.split("").reverse().join(""));
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result.entity).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(emitSpy).toHaveBeenCalledWith("created", {
|
||||
room: {
|
||||
name: "default",
|
||||
path: ["/foo/bar"],
|
||||
} as ResourcePath,
|
||||
resourcePath: "/foo/bar/baz",
|
||||
entity: "oloy",
|
||||
type: "string",
|
||||
result: {
|
||||
entity: "oloy",
|
||||
type: "string",
|
||||
context: undefined,
|
||||
operation: "create",
|
||||
raw: undefined,
|
||||
} as CreateResult<string>,
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
|
||||
it("should emit event with path computed from function", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeCreated<string>(input => [
|
||||
{ room: ResourcePath.get(`/foo/bar/${input}`), path: "/foo/bar/baz" },
|
||||
])
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
async reverseMeBaby(input: string): Promise<CreateResult<string>> {
|
||||
return new CreateResult<string>("string", input.split("").reverse().join(""));
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result.entity).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(emitSpy).toHaveBeenCalledWith("created", {
|
||||
room: {
|
||||
name: "default",
|
||||
path: ["/foo/bar/oloy"],
|
||||
} as ResourcePath,
|
||||
resourcePath: "/foo/bar/baz",
|
||||
entity: "oloy",
|
||||
type: "string",
|
||||
result: {
|
||||
entity: "oloy",
|
||||
context: undefined,
|
||||
operation: "create",
|
||||
type: "string",
|
||||
raw: undefined,
|
||||
} as CreateResult<string>,
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
});
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
import { describe, expect, it, jest } from "@jest/globals";
|
||||
import { DeleteResult } from "../../../../../../../src/core/platform/framework/api/crud-service";
|
||||
import { RealtimeDeleted } from "../../../../../../../src/core/platform/framework/decorators";
|
||||
import { websocketEventBus } from "../../../../../../../src/core/platform/services/realtime/bus";
|
||||
import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types";
|
||||
|
||||
describe("The RealtimeDeleted decorator", () => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeDeleted({ room: "/foo/bar" })
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
reverseMeBaby(input: string): Promise<string> {
|
||||
return Promise.resolve(input.split("").reverse().join(""));
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(0);
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
|
||||
it("should call the original method send back original result and emit event", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeDeleted({ room: "/foo/bar", path: "/foo/bar/baz" })
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
async reverseMeBaby(input: string): Promise<DeleteResult<string>> {
|
||||
return new DeleteResult<string>("string", input.split("").reverse().join(""), true);
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result.entity).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(emitSpy).toHaveBeenCalledWith("deleted", {
|
||||
room: {
|
||||
name: "default",
|
||||
path: ["/foo/bar"],
|
||||
} as ResourcePath,
|
||||
resourcePath: "/foo/bar/baz",
|
||||
entity: "oloy",
|
||||
type: "string",
|
||||
result: {
|
||||
entity: "oloy",
|
||||
context: undefined,
|
||||
operation: "delete",
|
||||
deleted: true,
|
||||
type: "string",
|
||||
} as DeleteResult<string>,
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
|
||||
it("should emit event with path computed from function", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeDeleted(result => [
|
||||
{ room: ResourcePath.get(`/foo/bar/${result}`), path: "/foo/bar/baz" },
|
||||
])
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
async reverseMeBaby(input: string): Promise<DeleteResult<string>> {
|
||||
return new DeleteResult<string>("string", input.split("").reverse().join(""), true);
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result.entity).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(emitSpy).toHaveBeenCalledWith("deleted", {
|
||||
room: {
|
||||
name: "default",
|
||||
path: ["/foo/bar/oloy"],
|
||||
} as ResourcePath,
|
||||
resourcePath: "/foo/bar/baz",
|
||||
entity: "oloy",
|
||||
type: "string",
|
||||
result: {
|
||||
entity: "oloy",
|
||||
context: undefined,
|
||||
operation: "delete",
|
||||
deleted: true,
|
||||
type: "string",
|
||||
} as DeleteResult<string>,
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
});
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
import { describe, expect, it, jest } from "@jest/globals";
|
||||
import { UpdateResult } from "../../../../../../../src/core/platform/framework/api/crud-service";
|
||||
import { RealtimeUpdated } from "../../../../../../../src/core/platform/framework/decorators";
|
||||
import { websocketEventBus } from "../../../../../../../src/core/platform/services/realtime/bus";
|
||||
import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types";
|
||||
|
||||
describe("The RealtimeUpdated decorator", () => {
|
||||
it("should call the original method send back original result but do not emit event if result type is wrong", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeUpdated({ room: "/foo/bar" })
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
reverseMeBaby(input: string): Promise<string> {
|
||||
return Promise.resolve(input.split("").reverse().join(""));
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(0);
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
|
||||
it("should call the original method send back original result and emit event", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeUpdated({ room: "/foo/bar", path: "/foo/bar/baz" })
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
async reverseMeBaby(input: string): Promise<UpdateResult<string>> {
|
||||
return new UpdateResult<string>("string", input.split("").reverse().join(""));
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result.entity).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(emitSpy).toHaveBeenCalledWith("updated", {
|
||||
entity: "oloy",
|
||||
room: {
|
||||
name: "default",
|
||||
path: ["/foo/bar"],
|
||||
} as ResourcePath,
|
||||
resourcePath: "/foo/bar/baz",
|
||||
type: "string",
|
||||
result: {
|
||||
type: "string",
|
||||
entity: "oloy",
|
||||
affected: undefined,
|
||||
context: undefined,
|
||||
operation: "update",
|
||||
raw: undefined,
|
||||
} as UpdateResult<string>,
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
|
||||
it("should emit event with path computed from function", async done => {
|
||||
const emitSpy = jest.spyOn(websocketEventBus, "emit");
|
||||
|
||||
class TestMe {
|
||||
@RealtimeUpdated(result => [
|
||||
{ room: ResourcePath.get(`/foo/bar/${result}`), path: "/foo/bar/baz" },
|
||||
])
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
async reverseMeBaby(input: string): Promise<UpdateResult<string>> {
|
||||
return new UpdateResult<string>("string", input.split("").reverse().join(""));
|
||||
}
|
||||
}
|
||||
|
||||
const test = new TestMe();
|
||||
const originalSpy = jest.spyOn(test, "reverseMeBaby");
|
||||
const result = await test.reverseMeBaby("yolo");
|
||||
|
||||
expect(result.entity).toEqual("oloy");
|
||||
expect(originalSpy).toHaveBeenCalledTimes(1);
|
||||
expect(originalSpy).toHaveBeenCalledWith("yolo");
|
||||
expect(emitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(emitSpy).toHaveBeenCalledWith("updated", {
|
||||
entity: "oloy",
|
||||
room: {
|
||||
name: "default",
|
||||
path: ["/foo/bar/oloy"],
|
||||
} as ResourcePath,
|
||||
resourcePath: "/foo/bar/baz",
|
||||
type: "string",
|
||||
result: {
|
||||
type: "string",
|
||||
context: undefined,
|
||||
operation: "update",
|
||||
entity: "oloy",
|
||||
affected: undefined,
|
||||
raw: undefined,
|
||||
} as UpdateResult<string>,
|
||||
});
|
||||
|
||||
emitSpy.mockRestore();
|
||||
done();
|
||||
});
|
||||
});
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
import "reflect-metadata";
|
||||
import { describe, expect, it } from "@jest/globals";
|
||||
import {
|
||||
buildSelectQuery,
|
||||
buildComparison,
|
||||
buildIn,
|
||||
} from "../../../../../../../../../src/core/platform/services/database/services/orm/connectors/cassandra/query-builder";
|
||||
import { ChannelMemberNotificationPreference } from "../../../../../../../../../src/services/notifications/entities/channel-member-notification-preferences";
|
||||
|
||||
describe("The QueryBuilder module", () => {
|
||||
describe("The buildSelectQuery function", () => {
|
||||
it("should build a valid query from primary key parameters", () => {
|
||||
const filters = {
|
||||
company_id: "comp1",
|
||||
channel_id: "chan1",
|
||||
};
|
||||
const result = buildSelectQuery<ChannelMemberNotificationPreference>(
|
||||
ChannelMemberNotificationPreference,
|
||||
filters,
|
||||
{},
|
||||
{ keyspace: "tdrive" },
|
||||
);
|
||||
|
||||
expect(result).toEqual(
|
||||
"SELECT * FROM tdrive.channel_members_notification_preferences WHERE company_id = comp1 AND channel_id = chan1;",
|
||||
);
|
||||
});
|
||||
|
||||
it("should build a valid query from primary key parameters and comparison", () => {
|
||||
const filters = {
|
||||
company_id: "comp1",
|
||||
channel_id: "chan1",
|
||||
};
|
||||
const result = buildSelectQuery<ChannelMemberNotificationPreference>(
|
||||
ChannelMemberNotificationPreference,
|
||||
filters,
|
||||
{
|
||||
$lt: [["last_read", 1000]],
|
||||
},
|
||||
{ keyspace: "tdrive" },
|
||||
);
|
||||
|
||||
expect(result).toEqual(
|
||||
"SELECT * FROM tdrive.channel_members_notification_preferences WHERE company_id = comp1 AND channel_id = chan1 AND last_read < 1000;",
|
||||
);
|
||||
});
|
||||
|
||||
it("should build IN query from array parameters", () => {
|
||||
const filters = {
|
||||
company_id: "comp1",
|
||||
channel_id: "chan1",
|
||||
user_id: ["u1", "u2", "u3"],
|
||||
};
|
||||
const result = buildSelectQuery<ChannelMemberNotificationPreference>(
|
||||
ChannelMemberNotificationPreference,
|
||||
filters,
|
||||
{},
|
||||
{ keyspace: "tdrive" },
|
||||
);
|
||||
|
||||
expect(result).toEqual(
|
||||
"SELECT * FROM tdrive.channel_members_notification_preferences WHERE company_id = comp1 AND channel_id = chan1 AND user_id IN (u1,u2,u3);",
|
||||
);
|
||||
});
|
||||
|
||||
it("should not build IN query from array parameters when array is empty", () => {
|
||||
const filters = {
|
||||
company_id: "comp1",
|
||||
channel_id: "chan1",
|
||||
user_id: [],
|
||||
};
|
||||
const result = buildSelectQuery<ChannelMemberNotificationPreference>(
|
||||
ChannelMemberNotificationPreference,
|
||||
filters,
|
||||
{},
|
||||
{ keyspace: "tdrive" },
|
||||
);
|
||||
|
||||
expect(result).toEqual(
|
||||
"SELECT * FROM tdrive.channel_members_notification_preferences WHERE company_id = comp1 AND channel_id = chan1;",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("The buildComparison function", () => {
|
||||
it("should create a valid < string", () => {
|
||||
expect(
|
||||
buildComparison({
|
||||
$lt: [["foo", 1]],
|
||||
}),
|
||||
).toContain("foo < 1");
|
||||
|
||||
const result = buildComparison({
|
||||
$lt: [
|
||||
["foo", 1],
|
||||
["bar", 2],
|
||||
],
|
||||
});
|
||||
|
||||
expect(result).toContain("foo < 1");
|
||||
expect(result).toContain("bar < 2");
|
||||
});
|
||||
|
||||
it("should create a valid <= string", () => {
|
||||
expect(
|
||||
buildComparison({
|
||||
$lte: [["foo", 1]],
|
||||
}),
|
||||
).toContain("foo <= 1");
|
||||
|
||||
const result = buildComparison({
|
||||
$lte: [
|
||||
["foo", 1],
|
||||
["bar", 2],
|
||||
],
|
||||
});
|
||||
|
||||
expect(result).toContain("foo <= 1");
|
||||
expect(result).toContain("bar <= 2");
|
||||
});
|
||||
|
||||
it("should create a valid > string", () => {
|
||||
expect(
|
||||
buildComparison({
|
||||
$gt: [["foo", 1]],
|
||||
}),
|
||||
).toContain("foo > 1");
|
||||
|
||||
const result = buildComparison({
|
||||
$gt: [
|
||||
["foo", 1],
|
||||
["bar", 2],
|
||||
],
|
||||
});
|
||||
|
||||
expect(result).toContain("foo > 1");
|
||||
expect(result).toContain("bar > 2");
|
||||
});
|
||||
|
||||
it("should create a valid >= string", () => {
|
||||
expect(
|
||||
buildComparison({
|
||||
$gte: [["foo", 1]],
|
||||
}),
|
||||
).toContain("foo >= 1");
|
||||
|
||||
const result = buildComparison({
|
||||
$gte: [
|
||||
["foo", 1],
|
||||
["bar", 2],
|
||||
],
|
||||
});
|
||||
|
||||
expect(result).toContain("foo >= 1");
|
||||
expect(result).toContain("bar >= 2");
|
||||
});
|
||||
|
||||
it("should combine conditions", () => {
|
||||
const result = buildComparison({
|
||||
$gt: [["foo", 1]],
|
||||
$gte: [["bar", 2]],
|
||||
$lt: [["baz", 3]],
|
||||
$lte: [["qix", 4]],
|
||||
});
|
||||
expect(result).toContain("foo > 1");
|
||||
expect(result).toContain("bar >= 2");
|
||||
expect(result).toContain("baz < 3");
|
||||
expect(result).toContain("qix <= 4");
|
||||
});
|
||||
});
|
||||
|
||||
describe("The buildIn function", () => {
|
||||
it("should create a id IN (ids) string", () => {
|
||||
expect(
|
||||
buildIn({
|
||||
$in: [["id", ["1", "2", "3"]]],
|
||||
}),
|
||||
).toContain("id IN (1,2,3)");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import "reflect-metadata";
|
||||
import { describe, expect, it } from "@jest/globals";
|
||||
import {
|
||||
fromMongoDbOrderable,
|
||||
toMongoDbOrderable,
|
||||
} from "../../../../../../src/core/platform/services/database/services/orm/utils";
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
import _ from "lodash";
|
||||
import { v1 as uuidv1 } from "uuid";
|
||||
|
||||
describe("The MongoDb to Orderable module", () => {
|
||||
describe("The to/from orderable function", () => {
|
||||
it("should be unique", () => {
|
||||
const uuid1 = toMongoDbOrderable(uuidv1());
|
||||
const uuid2 = toMongoDbOrderable(uuidv1());
|
||||
const uuid3 = toMongoDbOrderable(uuidv1());
|
||||
const uuid4 = toMongoDbOrderable(uuidv1());
|
||||
|
||||
expect(_.uniq([uuid1, uuid2, uuid3, uuid4]).length).toBe(4);
|
||||
});
|
||||
|
||||
it("should convert both ways", () => {
|
||||
const uuid = uuidv1();
|
||||
const orderable = toMongoDbOrderable(uuid);
|
||||
|
||||
expect(fromMongoDbOrderable(orderable)).toBe(uuid);
|
||||
expect(orderable).toBe(toMongoDbOrderable(fromMongoDbOrderable(orderable)));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from "@jest/globals";
|
||||
import { decrypt } from "../../../../../src/core/crypto/index";
|
||||
import v2 from "../../../../../src/core/crypto/v2";
|
||||
import v1 from "../../../../../src/core/crypto/v1";
|
||||
import legacy from "../../../../../src/core/crypto/legacy";
|
||||
|
||||
describe("Encryption", () => {
|
||||
const encryptionKey = "a7c06651a7c063bb3e90c0c9a17eab88ab8977665127196a";
|
||||
|
||||
describe("The encrypt/decrypt functions", () => {
|
||||
it("should successfully describe legacy encrypted values", async () => {
|
||||
const legacyEncrypted = "encrypted_DwMLnKhuFbIanqBJPA5rcw==";
|
||||
|
||||
expect(legacy.decrypt(legacyEncrypted, encryptionKey).data).toBe("My company");
|
||||
expect(decrypt(legacyEncrypted, encryptionKey).data).toBe("My company");
|
||||
});
|
||||
|
||||
it("should successfully describe all versions", async () => {
|
||||
const myData = { key: "some data" };
|
||||
|
||||
const v1Encrypted = v1.encrypt(myData, encryptionKey);
|
||||
const v2Encrypted = v2.encrypt(myData, encryptionKey);
|
||||
|
||||
expect(v1.decrypt(v1Encrypted.data, encryptionKey).data).toMatchObject(myData);
|
||||
expect(v2.decrypt(v2Encrypted.data, encryptionKey).data).toMatchObject(myData);
|
||||
|
||||
expect(decrypt(v1Encrypted.data, encryptionKey).data).toMatchObject(myData);
|
||||
expect(decrypt(v2Encrypted.data, encryptionKey).data).toMatchObject(myData);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from "@jest/globals";
|
||||
import * as pickUtils from "../../src/utils/pick";
|
||||
|
||||
describe("The pick utils", () => {
|
||||
describe("The pick function", () => {
|
||||
it("should return an object wich contains only the defined properties", () => {
|
||||
class TestClass {
|
||||
keep: string;
|
||||
me: string;
|
||||
skip: string;
|
||||
}
|
||||
|
||||
const keysToKeep = ["keep", "me"] as const;
|
||||
const object = { keep: "foo", me: "bar", skip: "baz" } as TestClass;
|
||||
const result = pickUtils.pick(object, ...keysToKeep);
|
||||
|
||||
expect(result).toEqual({ keep: "foo", me: "bar" });
|
||||
expect(result).not.toContain("skip");
|
||||
});
|
||||
|
||||
it("should return an empty object when input is empty", () => {
|
||||
class TestClass {
|
||||
keep: string;
|
||||
me: string;
|
||||
skip: string;
|
||||
}
|
||||
|
||||
const keysToKeep = [] as const;
|
||||
const object = { keep: "foo", me: "bar", skip: "baz" } as TestClass;
|
||||
const result = pickUtils.pick(object, ...keysToKeep);
|
||||
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user