1 import type { ItemRevision } from '@proton/pass/types';
2 import { CardType } from '@proton/pass/types/protobuf/item-v1';
3 import { obfuscate } from '@proton/pass/utils/obfuscate/xor';
5 import { searchItems } from './match-items';
7 const searchAndExpect = (items: ItemRevision[], expected: ItemRevision[]) => (search: string) => {
8 const result = searchItems(items, search);
9 expect(result).toEqual(expected);
12 describe('searchItems', () => {
20 note: obfuscate('This is item 1'),
24 itemEmail: obfuscate('user1@example.com'),
25 itemUsername: obfuscate('user1'),
26 urls: ['https://example.com'],
27 password: obfuscate(''),
28 totpUri: obfuscate('otpauth://totp/label?secret=secret&issuer=issuer'),
32 fieldName: 'hidden label',
35 content: obfuscate('hidden value'),
39 fieldName: 'text label',
42 content: obfuscate('text value'),
46 fieldName: 'totp label',
49 totpUri: obfuscate('otpauth://totp/label?secret=extrafieldsecret&issuer=issuer'),
60 note: obfuscate('This is item 2'),
71 name: 'Credit card item',
72 note: obfuscate('This is item 3'),
76 cardholderName: 'John Doe',
77 number: obfuscate('1234567890'),
78 verificationNumber: obfuscate(''),
80 cardType: CardType.Unspecified,
91 note: obfuscate('This is item 4'),
102 name: 'Identity item',
103 note: obfuscate('This is item 5'),
107 fullName: '::full-name::',
108 birthdate: '::birthdate::',
109 extraPersonalDetails: [
110 { fieldName: '::field::', type: 'text', data: { content: '::personal-detail-1::' } },
111 { fieldName: '::field::', type: 'hidden', data: { content: '::personal-detail-2::' } },
113 streetAddress: '::street-address::',
115 workEmail: '::work-email::',
117 { fieldName: '::field::', type: 'hidden', data: { content: '::work-detail-1::' } },
118 { fieldName: '::field::', type: 'text', data: { content: '::work-detail-2::' } },
122 sectionName: '::section-1::',
124 { fieldName: '::field::', type: 'text', data: { content: '::first-section-1::' } },
125 { fieldName: '::field::', type: 'hidden', data: { content: '::first-section-2::' } },
129 sectionName: '::section-2::',
131 { fieldName: '::field::', type: 'hidden', data: { content: '::second-section-1::' } },
132 { fieldName: '::field::', type: 'text', data: { content: '::second-section-2::' } },
143 { key: 'no search', search: [''], expected: items },
144 { key: 'note', search: ['this is item'], expected: [items[0], items[1], items[2], items[3], items[4]] },
147 search: ['Login item', 'user1@example.com', 'user1', 'example.com', 'text label', 'text value'],
148 expected: [items[0]],
150 { key: 'card item', search: ['John Doe', '1234567890'], expected: [items[2]] },
152 key: 'identity item',
159 '::personal-detail-2::',
165 expected: [items[4]],
167 ])('should return matching items based on $key', ({ search, expected }) => {
168 search.forEach(searchAndExpect(items, expected));
172 { key: 'query', search: 'db' },
173 { key: 'otp fields', search: 'otpauth://totp/label?secret=secret&issuer=issuer' },
174 { key: 'otp fields with extra fields', search: 'otpauth://totp/label?secret=extrafieldsecret&issuer=issuer' },
175 ])('should return empty array when no match $key', ({ search }) => {
176 searchAndExpect(items, [])(search);