Fix mocks
This commit is contained in:
parent
880d4ec15f
commit
ee62be63f1
|
@ -15,16 +15,17 @@ describe("AttachmentView", () => {
|
|||
attachment.size = "1000";
|
||||
attachment.sizeName = "kb";
|
||||
attachment.fileName = "my filename";
|
||||
attachment.key = new SymmetricCryptoKey(null);
|
||||
attachment.key = "encKey" as any;
|
||||
|
||||
jest.spyOn(SymmetricCryptoKey.prototype, "toJSON").mockImplementation(() => "not null value");
|
||||
|
||||
jest.spyOn(SymmetricCryptoKey, "fromJSON").mockImplementation(() => attachment.key);
|
||||
jest.spyOn(SymmetricCryptoKey, "fromJSON").mockImplementation(() => "encKeyfromJSON" as any);
|
||||
|
||||
const stringify = JSON.stringify(attachment);
|
||||
|
||||
const newAttachment = AttachmentView.fromJSON(JSON.parse(stringify));
|
||||
expect(newAttachment).toEqual(attachment);
|
||||
expect(newAttachment).toEqual({
|
||||
...attachment,
|
||||
key: "encKeyfromJSON",
|
||||
});
|
||||
expect(newAttachment).toBeInstanceOf(AttachmentView);
|
||||
|
||||
expect(SymmetricCryptoKey.fromJSON).toHaveBeenCalledTimes(1);
|
||||
|
|
|
@ -53,15 +53,21 @@ describe("CipherView", () => {
|
|||
const expected = new CipherView();
|
||||
Object.assign(expected, obj);
|
||||
|
||||
const mockCtor = (key: string) => key as any;
|
||||
jest.spyOn(LoginView, "fromJSON").mockImplementation(mockCtor);
|
||||
jest.spyOn(AttachmentView, "fromJSON").mockImplementation(mockCtor);
|
||||
jest.spyOn(FieldView, "fromJSON").mockImplementation(mockCtor);
|
||||
jest.spyOn(PasswordHistoryView, "fromJSON").mockImplementation(mockCtor);
|
||||
const mockFromJson = (key: string) => (key + "fromJSON") as any;
|
||||
jest.spyOn(LoginView, "fromJSON").mockImplementation(mockFromJson);
|
||||
jest.spyOn(AttachmentView, "fromJSON").mockImplementation(mockFromJson);
|
||||
jest.spyOn(FieldView, "fromJSON").mockImplementation(mockFromJson);
|
||||
jest.spyOn(PasswordHistoryView, "fromJSON").mockImplementation(mockFromJson);
|
||||
|
||||
const newCipher = CipherView.fromJSON(obj);
|
||||
|
||||
expect(newCipher).toEqual(expected);
|
||||
expect(newCipher).toEqual({
|
||||
...expected,
|
||||
login: "myLoginfromJSON",
|
||||
attachments: ["attachment1fromJSON", "attachment2fromJSON"],
|
||||
fields: ["field1fromJSON", "field2fromJSON"],
|
||||
passwordHistory: ["ph1fromJSON", "ph2fromJSON", "ph3fromJSON"],
|
||||
});
|
||||
expect(newCipher).toBeInstanceOf(CipherView);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,17 +15,18 @@ describe("LoginView", () => {
|
|||
login.totp = "totpSeed";
|
||||
login.autofillOnPageLoad = true;
|
||||
login.passwordRevisionDate = new Date();
|
||||
login.uris = [new LoginUriView()];
|
||||
login.uris = ["uri1", "uri2", "uri3"] as any;
|
||||
|
||||
jest
|
||||
.spyOn(LoginUriView.prototype, "toJSON")
|
||||
.mockImplementation(() => ({ mock: "not null value" }));
|
||||
jest.spyOn(LoginUriView, "fromJSON").mockImplementation(() => login.uris[0]);
|
||||
const mockFromJson = (key: string) => (key + "fromJSON") as any;
|
||||
jest.spyOn(LoginUriView, "fromJSON").mockImplementation(mockFromJson);
|
||||
|
||||
const stringified = JSON.stringify(login);
|
||||
const newLogin = LoginView.fromJSON(JSON.parse(stringified));
|
||||
|
||||
expect(newLogin).toEqual(login);
|
||||
expect(newLogin).toEqual({
|
||||
...login,
|
||||
uris: ["uri1fromJSON", "uri2fromJSON", "uri3fromJSON"],
|
||||
});
|
||||
expect(newLogin).toBeInstanceOf(LoginView);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue