|
| 1 | +import { expect, describe, test } from 'bun:test' |
| 2 | +import { InputLocations } from '../src/types' |
| 3 | +import { gitReadFunc } from '../src/git' |
| 4 | + |
| 5 | +const inputLocationsPromise: Promise<InputLocations> = await gitReadFunc( |
| 6 | + process.env['BRANCH']!, |
| 7 | + 'input-locations.json' |
| 8 | +).then(data => JSON.parse(data!)) |
| 9 | + |
| 10 | +describe('InputLocations', () => { |
| 11 | + test('json structure', async () => { |
| 12 | + const inputLocations = await inputLocationsPromise |
| 13 | + expect(typeof inputLocations === 'object', 'Json not valid: Not an array').toBe(true) |
| 14 | + expect(Array.isArray(inputLocations), 'Json not valid: Not an array').toBe(true) |
| 15 | + expect(inputLocations !== null, 'Json not valid: Not an array').toBe(true) |
| 16 | + }) |
| 17 | + |
| 18 | + describe('mods', async () => { |
| 19 | + const inputLocations = await inputLocationsPromise |
| 20 | + for (let i = 0; i < inputLocations.length; i++) { |
| 21 | + const loc = inputLocations[i] |
| 22 | + test(loc.url, async () => { |
| 23 | + expect( |
| 24 | + [undefined, 'zip'], |
| 25 | + 'type (type: string) must be one of: [undefined, "zip"]' |
| 26 | + ).toContain(loc.type) |
| 27 | + |
| 28 | + switch (loc.type) { |
| 29 | + case undefined: |
| 30 | + case 'zip': |
| 31 | + expect(loc.url).toBeTypeOf('string') |
| 32 | + expect( |
| 33 | + loc.source === undefined || typeof loc.source === 'string' |
| 34 | + ).toBeTrue() |
| 35 | + break |
| 36 | + } |
| 37 | + }) |
| 38 | + } |
| 39 | + }) |
| 40 | +}) |
0 commit comments