-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add e2e tests for config-import. (#700)
* add e2e tests for config-import. Additionally: * added `translation` getter in `mapeoProject` * `deleteAll(translation)` in import config * rename test * `deleteTranslations` only delete translations that refer to deleted fields or presets * better signature for delete functions, simplify `deleteTranslations` * simplify types * better error text * addressing review * make `deleteTranslations` a closure, pass the logger * `deleteTranslations` avoid for loop, use Promise.all(map) * make failing test case instead of logging * revert `deleteTranslations` being a closure * add boolean to avoid loading a config in parallel * refactor `deleteTranslations` Co-authored-by: Evan Hahn <[email protected]> * wrap importConfig in a try/catch * re-invert logic in `deleteTranslations` to please typescript * fix logic error, change assertion on parallel test * expose translationApi.dataType * fix type error * assert.throws -> assert.rejects Co-authored-by: Evan Hahn <[email protected]> * change test message * fix last test --------- Co-authored-by: Tomás Ciccola <[email protected]> Co-authored-by: Evan Hahn <[email protected]>
- Loading branch information
1 parent
bd492c4
commit 42bc021
Showing
3 changed files
with
219 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import test from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import { createManager } from './utils.js' | ||
import { defaultConfigPath } from '../tests/helpers/default-config.js' | ||
|
||
test(' config import - load default config when passed a path to `createProject`', async (t) => { | ||
const manager = createManager('device0', t) | ||
const project = await manager.getProject( | ||
await manager.createProject({ configPath: defaultConfigPath }) | ||
) | ||
const presets = await project.preset.getMany() | ||
const fields = await project.field.getMany() | ||
const translations = await project.$translation.dataType.getMany() | ||
assert.equal(presets.length, 28, 'correct number of loaded presets') | ||
assert.equal(fields.length, 11, 'correct number of loaded fields') | ||
assert.equal( | ||
translations.length, | ||
870, | ||
'correct number of loaded translations' | ||
) | ||
}) | ||
|
||
test('config import - load and re-load config manually', async (t) => { | ||
const manager = createManager('device0', t) | ||
const project = await manager.getProject(await manager.createProject()) | ||
|
||
const warnings = await project.importConfig({ configPath: defaultConfigPath }) | ||
let presets = await project.preset.getMany() | ||
let fields = await project.field.getMany() | ||
let translations = await project.$translation.dataType.getMany() | ||
|
||
assert.equal( | ||
warnings.length, | ||
0, | ||
'no warnings when manually loading default config' | ||
) | ||
assert.equal(presets.length, 28, 'correct number of manually loaded presets') | ||
assert.equal(fields.length, 11, 'correct number of manually loaded fields') | ||
assert.equal( | ||
translations.length, | ||
870, | ||
'correct number of manually loaded translations' | ||
) | ||
|
||
// re load the config | ||
await project.importConfig({ configPath: defaultConfigPath }) | ||
presets = await project.preset.getMany() | ||
fields = await project.field.getMany() | ||
translations = await project.$translation.dataType.getMany() | ||
assert.equal( | ||
presets.length, | ||
28, | ||
're-loading the same config leads to the same number of presets (since they are deleted)' | ||
) | ||
assert.equal( | ||
fields.length, | ||
11, | ||
're-loading the same config leads to the same number of fields (since they are deleted)' | ||
) | ||
assert.equal( | ||
translations.length, | ||
870, | ||
're-loading the same config leads to the same number of translations (since they are deleted)' | ||
) | ||
}) | ||
|
||
test('failing on loading multiple configs in parallel', async (t) => { | ||
const manager = createManager('device0', t) | ||
const project = await manager.getProject(await manager.createProject()) | ||
const results = await Promise.allSettled([ | ||
project.importConfig({ configPath: defaultConfigPath }), | ||
project.importConfig({ configPath: defaultConfigPath }), | ||
]) | ||
assert.equal(results[0]?.status, 'fulfilled', 'first import should work') | ||
assert.equal(results[1]?.status, 'rejected', 'second import should fail') | ||
}) |