Misc test tidy up

This commit is contained in:
Thomas Rittson 2022-06-29 13:42:15 +10:00
parent a9d7d4712e
commit da7e692f3e
3 changed files with 20 additions and 13 deletions

View File

@ -67,13 +67,20 @@ describe("SymmetricCryptoKey", () => {
});
});
it("serializes and deserializes", () => {
it("toJSON creates object for serialization", () => {
const key = new SymmetricCryptoKey(makeStaticByteArray(64).buffer);
const serialized = JSON.stringify(key);
const actual = key.toJSON();
const newKey = SymmetricCryptoKey.fromJSON(JSON.parse(serialized));
const expected = { keyB64: key.keyB64 };
expect(newKey).toEqual(key);
expect(newKey).toBeInstanceOf(SymmetricCryptoKey);
expect(actual).toEqual(expected);
});
it("fromJSON hydrates new object", () => {
const expected = new SymmetricCryptoKey(makeStaticByteArray(64).buffer);
const actual = SymmetricCryptoKey.fromJSON({ keyB64: expected.keyB64 });
expect(actual).toEqual(expected);
expect(actual).toBeInstanceOf(SymmetricCryptoKey);
});
});

View File

@ -46,7 +46,9 @@ describe("CipherView", () => {
const cipher = new CipherView();
Object.assign(cipher, testValues);
expect(cipher.toJSON()).toEqual(testValues);
const actual = cipher.toJSON();
expect(actual).toEqual(testValues);
});
it("fromJSON hydrates new view object", () => {
@ -56,8 +58,8 @@ describe("CipherView", () => {
jest.spyOn(FieldView, "fromJSON").mockImplementation(mockFromJson);
jest.spyOn(PasswordHistoryView, "fromJSON").mockImplementation(mockFromJson);
const parsedObject = JSON.parse(JSON.stringify(testValues));
const actual = CipherView.fromJSON(parsedObject);
const parsed = JSON.parse(JSON.stringify(testValues));
const actual = CipherView.fromJSON(parsed);
const expected = new CipherView();
Object.assign(expected, testValues, {

View File

@ -18,15 +18,13 @@ describe("LoginView", () => {
});
it("fromJSON hydrates new view object", () => {
const parsedFromJson = {
...testValues,
passwordRevisionDate: testValues.passwordRevisionDate.toISOString(),
};
const parsed = JSON.parse(JSON.stringify(testValues));
jest
.spyOn(LoginUriView, "fromJSON")
.mockImplementation((key: string) => (key + "fromJSON") as any);
const login = LoginView.fromJSON(parsedFromJson);
const login = LoginView.fromJSON(parsed);
expect(login).toEqual({
...testValues,