Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / components / hasValidAnonymousSignature.test.ts
blobc3d37f494d5c7cb1b1270a1b9f572011b5af8ffe
1 import { VERIFICATION_STATUS } from '@proton/srp/lib/constants';
3 import type { SignatureIssues } from '../store';
4 import { hasValidAnonymousSignature } from './hasValidAnonymousSignature';
6 describe('hasValidAnonymousSignature', () => {
7     beforeEach(() => {
8         // Spy on console.warn
9         jest.spyOn(console, 'warn').mockImplementation(() => {});
10     });
12     afterEach(() => {
13         jest.clearAllMocks();
14     });
16     it('should return true when thumbnail and blocks are NOT signed and others are valid', () => {
17         const signatureIssues: SignatureIssues = {
18             manifest: VERIFICATION_STATUS.SIGNED_AND_VALID,
19             thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
20             blocks: VERIFICATION_STATUS.NOT_SIGNED,
21             passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
22         };
24         expect(hasValidAnonymousSignature(signatureIssues)).toBe(true);
25     });
27     it('should return false when thumbnail is signed', () => {
28         const signatureIssues: SignatureIssues = {
29             manifest: VERIFICATION_STATUS.SIGNED_AND_VALID,
30             thumbnail: VERIFICATION_STATUS.SIGNED_AND_VALID,
31             blocks: VERIFICATION_STATUS.NOT_SIGNED,
32             passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
33         };
35         expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
36         expect(console.warn).toHaveBeenCalledWith(
37             'thumbnail signature should not be signed in case of anonymous upload'
38         );
39     });
41     it('should return false when blocks are signed', () => {
42         const signatureIssues: SignatureIssues = {
43             manifest: VERIFICATION_STATUS.SIGNED_AND_VALID,
44             thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
45             blocks: VERIFICATION_STATUS.SIGNED_AND_VALID,
46             passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
47         };
49         expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
50         expect(console.warn).toHaveBeenCalledWith('blocks signature should not be signed in case of anonymous upload');
51     });
53     it('should return false when non-thumbnail/blocks signatures are invalid', () => {
54         const signatureIssues: SignatureIssues = {
55             manifest: VERIFICATION_STATUS.SIGNED_AND_INVALID,
56             thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
57             blocks: VERIFICATION_STATUS.NOT_SIGNED,
58             passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
59         };
61         expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
62     });
64     it('should return false when non-thumbnail/blocks signatures are not signed', () => {
65         const signatureIssues: SignatureIssues = {
66             manifest: VERIFICATION_STATUS.NOT_SIGNED,
67             thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
68             blocks: VERIFICATION_STATUS.NOT_SIGNED,
69             passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
70         };
72         expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
73     });
75     it('should handle empty signature issues object', () => {
76         const signatureIssues: SignatureIssues = {};
78         expect(hasValidAnonymousSignature(signatureIssues)).toBe(true);
79     });
80 });