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.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);
|
||||
});
|
||||
|
||||
@@ -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 = {
|
||||
key: 'value',
|
||||
};
|
||||
|
||||
const appAuthClient = await createAppAuthClient({
|
||||
formattedAuthDefaults,
|
||||
});
|
||||
const authDefaults = AES.encrypt(
|
||||
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
|
||||
);
|
||||
expect(appAuthClient.authDefaults).not.toEqual(formattedAuthDefaults);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eligibleForEncryption', () => {
|
||||
|
Reference in New Issue
Block a user