Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ps 1291/apply to from json pattern to state #3425

Merged
merged 34 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ee6258b
Clean up dangling behaviorSubject
MGibson1 Aug 31, 2022
1fb6207
Handle null in utils
MGibson1 Aug 31, 2022
df40c8b
fix null check
MGibson1 Aug 31, 2022
719a6d0
Await promises, even in async functions
MGibson1 Aug 31, 2022
77bbd3a
Add to/fromJSON methods to State and Accounts
MGibson1 Aug 31, 2022
5370cc4
Simplify AccountKeys json parsing
MGibson1 Sep 1, 2022
b1dffb5
Fix account key (de)serialization
MGibson1 Sep 13, 2022
625f0f4
Remove unused DecodedToken state
MGibson1 Sep 13, 2022
3ec36f9
Correct filename typo
MGibson1 Sep 13, 2022
e42e15f
Simplify keys `toJSON` tests
MGibson1 Sep 13, 2022
6954668
Explain AccountKeys `toJSON` return type
MGibson1 Sep 13, 2022
a5739c6
Remove unnecessary `any`s
MGibson1 Sep 16, 2022
ae530cb
Remove unique ArrayBuffer serialization
MGibson1 Sep 16, 2022
39640a1
Initialize items in MemoryStorageService
MGibson1 Sep 16, 2022
c0da43b
Revert "Fix account key (de)serialization"
MGibson1 Sep 16, 2022
02ac04c
Move fromJSON to owning object
MGibson1 Sep 19, 2022
d3bd66a
Add DeepJsonify type
MGibson1 Sep 19, 2022
0a4da3f
Use Records for storage
MGibson1 Sep 20, 2022
65198f9
Merge remote-tracking branch 'origin/master' into PS-1291/apply-to-fr…
MGibson1 Sep 20, 2022
f508558
Add new Account Settings to serialized data
MGibson1 Sep 20, 2022
f5af75d
Fix failing serialization tests
MGibson1 Sep 20, 2022
fbff8ce
Extract complex type conversion to helper methods
MGibson1 Sep 21, 2022
a435116
Remove unnecessary decorator
MGibson1 Sep 21, 2022
a9df102
Return null from json deserializers
MGibson1 Sep 21, 2022
b0b36ae
Remove unnecessary decorators
MGibson1 Sep 21, 2022
33e8ed7
Remove obsolete test
MGibson1 Sep 21, 2022
7f44bdd
Use type-fest `Jsonify` formatting rules for external library
MGibson1 Sep 21, 2022
bf014c6
Update jsonify comment
MGibson1 Sep 21, 2022
618bc89
Remove erroneous comment
MGibson1 Sep 21, 2022
8d6ec8d
Fix unintended deep-jsonify changes
MGibson1 Sep 21, 2022
65b6617
Merge remote-tracking branch 'origin/master' into PS-1291/apply-to-fr…
MGibson1 Sep 21, 2022
338263c
Fix prettierignore
MGibson1 Sep 22, 2022
ffca5f3
Fix formatting of deep-jsonify.ts
eliykat Sep 22, 2022
fe4a320
Merge branch 'master' into PS-1291/apply-to-from-json-pattern-to-state
eliykat Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 0 additions & 82 deletions libs/common/spec/services/state.service.spec.ts

This file was deleted.

55 changes: 55 additions & 0 deletions libs/common/src/models/data/server-config.data.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
EnvironmentServerConfigData,
ServerConfigData,
ThirdPartyServerConfigData,
} from "./server-config.data";

describe("ServerConfigData", () => {
describe("fromJSON", () => {
it("should create a ServerConfigData from a JSON object", () => {
const serverConfigData = ServerConfigData.fromJSON({
version: "1.0.0",
gitHash: "1234567890",
server: {
name: "test",
url: "https://test.com",
},
environment: {
vault: "https://vault.com",
api: "https://api.com",
identity: "https://identity.com",
notifications: "https://notifications.com",
sso: "https://sso.com",
},
utcDate: "2020-01-01T00:00:00.000Z",
});

expect(serverConfigData.version).toEqual("1.0.0");
expect(serverConfigData.gitHash).toEqual("1234567890");
expect(serverConfigData.server.name).toEqual("test");
expect(serverConfigData.server.url).toEqual("https://test.com");
expect(serverConfigData.environment.vault).toEqual("https://vault.com");
expect(serverConfigData.environment.api).toEqual("https://api.com");
expect(serverConfigData.environment.identity).toEqual("https://identity.com");
expect(serverConfigData.environment.notifications).toEqual("https://notifications.com");
expect(serverConfigData.environment.sso).toEqual("https://sso.com");
expect(serverConfigData.utcDate).toEqual("2020-01-01T00:00:00.000Z");
});

it("should be an instance of ServerConfigData", () => {
const serverConfigData = ServerConfigData.fromJSON({} as any);

expect(serverConfigData).toBeInstanceOf(ServerConfigData);
});

it("should deserialize sub objects", () => {
const serverConfigData = ServerConfigData.fromJSON({
server: {},
environment: {},
} as any);

expect(serverConfigData.server).toBeInstanceOf(ThirdPartyServerConfigData);
expect(serverConfigData.environment).toBeInstanceOf(EnvironmentServerConfigData);
});
});
});
35 changes: 26 additions & 9 deletions libs/common/src/models/data/server-config.data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Jsonify } from "type-fest";

import {
ServerConfigResponse,
ThirdPartyServerConfigResponse,
Expand All @@ -11,27 +13,38 @@ export class ServerConfigData {
environment?: EnvironmentServerConfigData;
utcDate: string;

constructor(serverConfigReponse: ServerConfigResponse) {
this.version = serverConfigReponse?.version;
this.gitHash = serverConfigReponse?.gitHash;
this.server = serverConfigReponse?.server
? new ThirdPartyServerConfigData(serverConfigReponse.server)
constructor(serverConfigResponse: Partial<ServerConfigResponse>) {
this.version = serverConfigResponse?.version;
this.gitHash = serverConfigResponse?.gitHash;
this.server = serverConfigResponse?.server
? new ThirdPartyServerConfigData(serverConfigResponse.server)
: null;
this.utcDate = new Date().toISOString();
this.environment = serverConfigReponse?.environment
? new EnvironmentServerConfigData(serverConfigReponse.environment)
this.environment = serverConfigResponse?.environment
? new EnvironmentServerConfigData(serverConfigResponse.environment)
: null;
}

static fromJSON(obj: Jsonify<ServerConfigData>): ServerConfigData {
return Object.assign(new ServerConfigData({}), obj, {
server: obj?.server ? ThirdPartyServerConfigData.fromJSON(obj.server) : null,
environment: obj?.environment ? EnvironmentServerConfigData.fromJSON(obj.environment) : null,
});
}
}

export class ThirdPartyServerConfigData {
name: string;
url: string;

constructor(response: ThirdPartyServerConfigResponse) {
constructor(response: Partial<ThirdPartyServerConfigResponse>) {
this.name = response.name;
this.url = response.url;
}

static fromJSON(obj: Jsonify<ThirdPartyServerConfigData>): ThirdPartyServerConfigData {
return Object.assign(new ThirdPartyServerConfigData({}), obj);
}
}

export class EnvironmentServerConfigData {
Expand All @@ -41,11 +54,15 @@ export class EnvironmentServerConfigData {
notifications: string;
sso: string;

constructor(response: EnvironmentServerConfigResponse) {
constructor(response: Partial<EnvironmentServerConfigResponse>) {
this.vault = response.vault;
this.api = response.api;
this.identity = response.identity;
this.notifications = response.notifications;
this.sso = response.sso;
}

static fromJSON(obj: Jsonify<EnvironmentServerConfigData>): EnvironmentServerConfigData {
return Object.assign(new EnvironmentServerConfigData({}), obj);
}
}
24 changes: 9 additions & 15 deletions libs/common/src/models/domain/account-keys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@ describe("AccountKeys", () => {
it("should serialize itself", () => {
const keys = new AccountKeys();
const buffer = makeStaticByteArray(64).buffer;
const symmetricKey = new SymmetricCryptoKey(buffer);
keys.cryptoMasterKey = symmetricKey;
keys.publicKey = buffer;
keys.cryptoSymmetricKey = new EncryptionPair<string, SymmetricCryptoKey>();
keys.cryptoSymmetricKey.decrypted = symmetricKey;

const symmetricKeySpy = jest.spyOn(symmetricKey, "toJSON");
const actual = keys.toJSON();
expect(symmetricKeySpy).toHaveBeenCalled();
expect(actual).toContain(`"cryptoMasterKey":${JSON.stringify(symmetricKey.toJSON())}`);
expect(actual).toContain(
`"publicKeySerialized":${JSON.stringify(Utils.fromBufferToByteString(buffer))}`
);
const bufferSpy = jest.spyOn(Utils, "fromBufferToByteString");
keys.toJSON();
expect(bufferSpy).toHaveBeenCalledWith(buffer);
});

it("should serialize public key as a string", () => {
Expand All @@ -43,25 +35,27 @@ describe("AccountKeys", () => {

it("should deserialize cryptoMasterKey", () => {
const spy = jest.spyOn(SymmetricCryptoKey, "fromJSON");
AccountKeys.fromJSON({});
AccountKeys.fromJSON({} as any);
expect(spy).toHaveBeenCalled();
});

it("should deserialize organizationKeys", () => {
const spy = jest.spyOn(SymmetricCryptoKey, "fromJSON");
AccountKeys.fromJSON({ organizationKeys: [{ orgId: "keyJSON" }] });
AccountKeys.fromJSON({ organizationKeys: [{ orgId: "keyJSON" }] } as any);
expect(spy).toHaveBeenCalled();
});

it("should deserialize providerKeys", () => {
const spy = jest.spyOn(SymmetricCryptoKey, "fromJSON");
AccountKeys.fromJSON({ providerKeys: [{ providerId: "keyJSON" }] });
AccountKeys.fromJSON({ providerKeys: [{ providerId: "keyJSON" }] } as any);
expect(spy).toHaveBeenCalled();
});

it("should deserialize privateKey", () => {
const spy = jest.spyOn(EncryptionPair, "fromJSON");
AccountKeys.fromJSON({ privateKey: { encrypted: "encrypted", decrypted: "decrypted" } });
AccountKeys.fromJSON({
privateKey: { encrypted: "encrypted", decrypted: "decrypted" },
} as any);
expect(spy).toHaveBeenCalled();
});
});
Expand Down
Loading