-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathuploaded-profiles-db.test.ts
More file actions
93 lines (81 loc) · 2.92 KB
/
uploaded-profiles-db.test.ts
File metadata and controls
93 lines (81 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Main use cases of storing profiles are tested in the publish flow
// (test/store/publish.test.js). In this file we'll test more specific cases.
import {
persistUploadedProfileInformationToDb,
listAllUploadedProfileInformationFromDb,
retrieveUploadedProfileInformationFromDb,
deleteUploadedProfileInformationFromDb,
type UploadedProfileInformation,
} from 'firefox-profiler/app-logic/uploaded-profiles-db';
import { autoMockIndexedDB } from 'firefox-profiler/test/fixtures/mocks/indexeddb';
autoMockIndexedDB();
describe('uploaded-profiles-db', function () {
async function storeGenericUploadedProfileInformation(
overrides: Partial<UploadedProfileInformation>
) {
const basicUploadedProfileInformation = {
profileToken: 'PROFILE-1',
jwtToken: null,
publishedDate: new Date(),
name: '',
preset: null,
meta: {
product: 'Firefox',
},
urlPath: '/',
publishedRange: { start: 1000, end: 3000 },
};
await persistUploadedProfileInformationToDb({
...basicUploadedProfileInformation,
...overrides,
});
}
async function setup() {
await storeGenericUploadedProfileInformation({
profileToken: 'PROFILE-1',
publishedDate: new Date('2020-07-01'),
});
await storeGenericUploadedProfileInformation({
profileToken: 'PROFILE-2',
publishedDate: new Date('2018-07-01'),
});
await storeGenericUploadedProfileInformation({
profileToken: 'PROFILE-3',
publishedDate: new Date('2019-07-01'),
});
}
it('retrieves individual profile information', async () => {
await setup();
expect(
await retrieveUploadedProfileInformationFromDb('PROFILE-1')
).toMatchObject({
profileToken: 'PROFILE-1',
});
});
it('retrieves a sorted list', async () => {
// 1. Store some profile data in an unsorted order.
await setup();
// 2. Retrieve the list and expect it's in the expected sorted order.
const listOfUploadedProfileInformation =
await listAllUploadedProfileInformationFromDb();
expect(listOfUploadedProfileInformation).toEqual([
expect.objectContaining({ profileToken: 'PROFILE-2' }),
expect.objectContaining({ profileToken: 'PROFILE-3' }),
expect.objectContaining({ profileToken: 'PROFILE-1' }),
]);
});
it('can delete profile information', async () => {
await setup();
await deleteUploadedProfileInformationFromDb('PROFILE-2');
expect(await retrieveUploadedProfileInformationFromDb('PROFILE-2')).toBe(
null
);
expect(await listAllUploadedProfileInformationFromDb()).toEqual([
expect.objectContaining({ profileToken: 'PROFILE-3' }),
expect.objectContaining({ profileToken: 'PROFILE-1' }),
]);
});
});