2022-10-10 17:19:01 +02:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2022-09-27 03:17:43 +02:00
|
|
|
import { Substitute, Arg } from "@fluffy-spoon/substitute";
|
2022-04-16 17:18:12 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { SendType } from "@bitwarden/common/enums/sendType";
|
2022-10-14 18:25:50 +02:00
|
|
|
import { SendAccess } from "@bitwarden/common/models/domain/send-access";
|
|
|
|
import { SendText } from "@bitwarden/common/models/domain/send-text";
|
2022-10-18 19:01:42 +02:00
|
|
|
import { SendAccessResponse } from "@bitwarden/common/models/response/send-access.response";
|
2022-04-16 17:18:12 +02:00
|
|
|
|
2022-08-05 00:07:24 +02:00
|
|
|
import { mockEnc } from "../../utils";
|
2022-04-16 17:18:12 +02:00
|
|
|
|
|
|
|
describe("SendAccess", () => {
|
|
|
|
let request: SendAccessResponse;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
request = {
|
|
|
|
id: "id",
|
|
|
|
type: SendType.Text,
|
|
|
|
name: "encName",
|
|
|
|
file: null,
|
|
|
|
text: {
|
|
|
|
text: "encText",
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
expirationDate: new Date("2022-01-31T12:00:00.000Z"),
|
|
|
|
creatorIdentifier: "creatorIdentifier",
|
|
|
|
} as SendAccessResponse;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Convert from empty", () => {
|
|
|
|
const request = new SendAccessResponse({});
|
|
|
|
const sendAccess = new SendAccess(request);
|
|
|
|
|
|
|
|
expect(sendAccess).toEqual({
|
|
|
|
id: null,
|
|
|
|
type: undefined,
|
|
|
|
name: null,
|
|
|
|
creatorIdentifier: null,
|
|
|
|
expirationDate: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Convert", () => {
|
|
|
|
const sendAccess = new SendAccess(request);
|
|
|
|
|
|
|
|
expect(sendAccess).toEqual({
|
|
|
|
id: "id",
|
|
|
|
type: 0,
|
|
|
|
name: { encryptedString: "encName", encryptionType: 0 },
|
|
|
|
text: {
|
|
|
|
hidden: true,
|
|
|
|
text: { encryptedString: "encText", encryptionType: 0 },
|
|
|
|
},
|
|
|
|
expirationDate: new Date("2022-01-31T12:00:00.000Z"),
|
|
|
|
creatorIdentifier: "creatorIdentifier",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Decrypt", async () => {
|
|
|
|
const sendAccess = new SendAccess();
|
|
|
|
sendAccess.id = "id";
|
|
|
|
sendAccess.type = SendType.Text;
|
|
|
|
sendAccess.name = mockEnc("name");
|
|
|
|
|
|
|
|
const text = Substitute.for<SendText>();
|
|
|
|
text.decrypt(Arg.any()).resolves({} as any);
|
|
|
|
sendAccess.text = text;
|
|
|
|
|
|
|
|
sendAccess.expirationDate = new Date("2022-01-31T12:00:00.000Z");
|
|
|
|
sendAccess.creatorIdentifier = "creatorIdentifier";
|
|
|
|
|
|
|
|
const view = await sendAccess.decrypt(null);
|
|
|
|
|
|
|
|
text.received(1).decrypt(Arg.any());
|
|
|
|
|
|
|
|
expect(view).toEqual({
|
|
|
|
id: "id",
|
|
|
|
type: 0,
|
|
|
|
name: "name",
|
|
|
|
text: {},
|
|
|
|
file: expect.anything(),
|
|
|
|
expirationDate: new Date("2022-01-31T12:00:00.000Z"),
|
|
|
|
creatorIdentifier: "creatorIdentifier",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|