|
| 1 | +import type { ApiClient } from '$endpoints'; |
| 2 | +import { beforeEach, describe, expect, it } from 'vitest'; |
| 3 | +import { setup } from '../../helpers'; |
| 4 | +import { migrateDataFromZip, migratePrivateDataFromZip } from '../migration'; |
| 5 | +import path from 'path'; |
| 6 | +import itemId from '$lib/itemId'; |
| 7 | + |
| 8 | +let api: ApiClient; |
| 9 | + |
| 10 | +beforeEach(async () => { |
| 11 | + api = (await setup()).api; |
| 12 | +}); |
| 13 | + |
| 14 | +describe('Public data', () => { |
| 15 | + beforeEach(async () => { |
| 16 | + await migrateDataFromZip(path.join(__dirname, 'data.zip')); |
| 17 | + }); |
| 18 | + |
| 19 | + it('Correctly creates all items', async () => { |
| 20 | + await expect(api.item(itemId.ROOT).info.get()).resolves.toMatchObject({ |
| 21 | + children: ['group'] |
| 22 | + }); |
| 23 | + |
| 24 | + await expect(api.item(itemId.fromStr('/group')).info.get()).resolves.toMatchObject({ |
| 25 | + // Only listed child is listed |
| 26 | + children: ['listed'] |
| 27 | + }); |
| 28 | + |
| 29 | + // Both children resolve |
| 30 | + await expect(api.item(itemId.fromStr('/group/listed')).info.get()).toResolve(); |
| 31 | + await expect(api.item(itemId.fromStr('/group/unlisted')).info.get()).toResolve(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('Migrates URL sections correctly', async () => { |
| 35 | + await expect(api.item(itemId.fromStr('/group/listed')).info.get()).resolves.toMatchObject({ |
| 36 | + sections: expect.arrayContaining([ |
| 37 | + { |
| 38 | + type: 'site', |
| 39 | + url: 'https://example.com', |
| 40 | + // Uses default icon and label |
| 41 | + icon: null, |
| 42 | + label: null, |
| 43 | + }, |
| 44 | + ]) |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('Migrates link sections correctly', async () => { |
| 49 | + await expect(api.item(itemId.fromStr('/group/listed')).info.get()).resolves.toMatchObject({ |
| 50 | + sections: expect.arrayContaining([ |
| 51 | + { |
| 52 | + type: 'links', |
| 53 | + label: 'See also', |
| 54 | + items: ['/group/unlisted'], |
| 55 | + style: 'card', |
| 56 | + }, |
| 57 | + ]) |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
| 61 | + |
| 62 | +it('Migrates private data correctly', async () => { |
| 63 | + await migratePrivateDataFromZip(path.join(__dirname, 'private_data.zip')); |
| 64 | + // We can still log in |
| 65 | + await expect(api.admin.auth.login('maddy', 'Maddy123#')).toResolve(); |
| 66 | +}); |
0 commit comments