test(models/app-auth-client): improve decrypt data test cases
This commit is contained in:
@@ -41,7 +41,14 @@ describe('AppAuthClient model', () => {
|
|||||||
appAuthClient.formattedAuthDefaults = formattedAuthDefaults;
|
appAuthClient.formattedAuthDefaults = formattedAuthDefaults;
|
||||||
appAuthClient.encryptData();
|
appAuthClient.encryptData();
|
||||||
|
|
||||||
expect(appAuthClient.authDefaults).toBeDefined();
|
const expectedDecryptedValue = JSON.parse(
|
||||||
|
AES.decrypt(
|
||||||
|
appAuthClient.authDefaults,
|
||||||
|
appConfig.encryptionKey
|
||||||
|
).toString(enc)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(formattedAuthDefaults).toStrictEqual(expectedDecryptedValue);
|
||||||
expect(appAuthClient.authDefaults).not.toEqual(formattedAuthDefaults);
|
expect(appAuthClient.authDefaults).not.toEqual(formattedAuthDefaults);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -63,20 +70,42 @@ describe('AppAuthClient model', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('decryptData should decrypt authDefaults and set it to formattedAuthDefaults', async () => {
|
describe('decryptData', () => {
|
||||||
|
it('should return undefined if eligibleForDecryption is not true', () => {
|
||||||
|
vi.spyOn(
|
||||||
|
AppAuthClient.prototype,
|
||||||
|
'eligibleForDecryption'
|
||||||
|
).mockReturnValue(false);
|
||||||
|
|
||||||
|
const appAuthClient = new AppAuthClient();
|
||||||
|
|
||||||
|
expect(appAuthClient.decryptData()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should decrypt authDefaults and set it to formattedAuthDefaults', async () => {
|
||||||
|
vi.spyOn(
|
||||||
|
AppAuthClient.prototype,
|
||||||
|
'eligibleForDecryption'
|
||||||
|
).mockReturnValue(true);
|
||||||
|
|
||||||
const formattedAuthDefaults = {
|
const formattedAuthDefaults = {
|
||||||
key: 'value',
|
key: 'value',
|
||||||
};
|
};
|
||||||
|
|
||||||
const appAuthClient = await createAppAuthClient({
|
const authDefaults = AES.encrypt(
|
||||||
formattedAuthDefaults,
|
JSON.stringify(formattedAuthDefaults),
|
||||||
});
|
appConfig.encryptionKey
|
||||||
|
).toString();
|
||||||
|
|
||||||
const refetchedAppAuthClient = await appAuthClient.$query();
|
const appAuthClient = new AppAuthClient();
|
||||||
|
appAuthClient.authDefaults = authDefaults;
|
||||||
|
appAuthClient.decryptData();
|
||||||
|
|
||||||
expect(refetchedAppAuthClient.formattedAuthDefaults).toStrictEqual(
|
expect(appAuthClient.formattedAuthDefaults).toStrictEqual(
|
||||||
formattedAuthDefaults
|
formattedAuthDefaults
|
||||||
);
|
);
|
||||||
|
expect(appAuthClient.authDefaults).not.toEqual(formattedAuthDefaults);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('eligibleForEncryption', () => {
|
describe('eligibleForEncryption', () => {
|
||||||
|
Reference in New Issue
Block a user