-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: load default config when creating a project #471
Changes from all commits
15733dc
9edd313
615cfe6
bed0244
d5e62cc
3fe385c
076e5ba
d5d0b77
dc078d9
37806e8
8dc066a
6e1923e
dcb9410
e5ee544
c16b9fd
53f981f
4755ae0
869199b
8b4268c
315acf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import { KeyManager } from '@mapeo/crypto' | |
import RAM from 'random-access-memory' | ||
import { MapeoManager } from '../src/mapeo-manager.js' | ||
import Fastify from 'fastify' | ||
import { getExpectedConfig } from './utils.js' | ||
import { kDataTypes } from '../src/mapeo-project.js' | ||
|
||
const projectMigrationsFolder = new URL('../drizzle/project', import.meta.url) | ||
.pathname | ||
|
@@ -26,7 +28,7 @@ test('Managing created projects', async (t) => { | |
name: 'project 2', | ||
}) | ||
|
||
t.test('initial information from listed projects', async (st) => { | ||
await t.test('initial information from listed projects', async (st) => { | ||
const listedProjects = await manager.listProjects() | ||
|
||
st.is(listedProjects.length, 2) | ||
|
@@ -56,22 +58,23 @@ test('Managing created projects', async (t) => { | |
t.ok(project1) | ||
t.ok(project2) | ||
|
||
t.test('initial settings from project instances', async (st) => { | ||
await t.test('initial settings from project instances', async (st) => { | ||
const settings1 = await project1.$getProjectSettings() | ||
const settings2 = await project2.$getProjectSettings() | ||
|
||
st.alike(settings1, { | ||
name: undefined, | ||
defaultPresets: undefined, | ||
}) | ||
|
||
st.alike(settings2, { | ||
name: 'project 2', | ||
defaultPresets: undefined, | ||
}) | ||
st.alike( | ||
settings1, | ||
{ name: undefined, defaultPresets: undefined }, | ||
'undefined name and default presets for project1' | ||
) | ||
st.alike( | ||
settings2, | ||
{ name: 'project 2', defaultPresets: undefined }, | ||
'matched name for project2 with undefined default presets' | ||
) | ||
}) | ||
|
||
t.test('after updating project settings', async (st) => { | ||
await t.test('after updating project settings', async (st) => { | ||
await project1.$setProjectSettings({ | ||
name: 'project 1', | ||
}) | ||
|
@@ -82,15 +85,9 @@ test('Managing created projects', async (t) => { | |
const settings1 = await project1.$getProjectSettings() | ||
const settings2 = await project2.$getProjectSettings() | ||
|
||
st.alike(settings1, { | ||
name: 'project 1', | ||
defaultPresets: undefined, | ||
}) | ||
st.is(settings1.name, 'project 1') | ||
|
||
st.alike(settings2, { | ||
name: 'project 2 updated', | ||
defaultPresets: undefined, | ||
}) | ||
st.is(settings2.name, 'project 2 updated') | ||
|
||
const listedProjects = await manager.listProjects() | ||
|
||
|
@@ -116,6 +113,89 @@ test('Managing created projects', async (t) => { | |
}) | ||
}) | ||
|
||
test('Consistent loading of config', async (t) => { | ||
const manager = new MapeoManager({ | ||
rootKey: KeyManager.generateRootKey(), | ||
projectMigrationsFolder, | ||
clientMigrationsFolder, | ||
dbFolder: ':memory:', | ||
coreStorage: () => new RAM(), | ||
fastify: Fastify(), | ||
defaultConfigPath: 'config/defaultConfig.mapeoconfig', | ||
}) | ||
|
||
const expectedDefault = await getExpectedConfig( | ||
'config/defaultConfig.mapeoconfig' | ||
) | ||
const expectedMinimal = await getExpectedConfig( | ||
'tests/fixtures/config/completeConfig.zip' | ||
) | ||
const projectId = await manager.createProject() | ||
const project = await manager.getProject(projectId) | ||
const projectSettings = await project.$getProjectSettings() | ||
|
||
const projectPresets = await project.preset.getMany() | ||
await t.test( | ||
'load default config and check if correctly loaded', | ||
async (st) => { | ||
st.is( | ||
//@ts-ignore | ||
projectSettings.defaultPresets.point.length, | ||
expectedDefault.presets.length, | ||
'the default presets loaded is equal to the number of presets in the default config' | ||
) | ||
|
||
st.alike( | ||
projectPresets.map((preset) => preset.name), | ||
expectedDefault.presets.map((preset) => preset.value.name), | ||
'project is loading the default presets correctly' | ||
) | ||
|
||
const projectFields = await project.field.getMany() | ||
st.alike( | ||
projectFields.map((field) => field.tagKey), | ||
expectedDefault.fields.map((field) => field.value.tagKey), | ||
'project is loading the default fields correctly' | ||
) | ||
|
||
const projectIcons = await project[kDataTypes].icon.getMany() | ||
st.alike( | ||
projectIcons.map((icon) => icon.name), | ||
expectedDefault.icons.map((icon) => icon.name), | ||
'project is loading the default icons correctly' | ||
) | ||
} | ||
) | ||
|
||
await t.test( | ||
'load different config and check if correctly loaded', | ||
async (st) => { | ||
Comment on lines
+170
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think things can get confusing when you have subtests that mutate the project, maybe move to a separate test and a separate project instances? I don't think this needs to be part of the same test. |
||
const configPath = 'tests/fixtures/config/completeConfig.zip' | ||
await project.importConfig({ configPath }) | ||
const projectPresets = await project.preset.getMany() | ||
st.alike( | ||
projectPresets.map((preset) => preset.name), | ||
expectedMinimal.presets.map((preset) => preset.value.name), | ||
'project presets explicitly loaded match expected config' | ||
) | ||
|
||
const projectFields = await project.field.getMany() | ||
st.alike( | ||
projectFields.map((field) => field.tagKey), | ||
expectedMinimal.fields.map((field) => field.value.tagKey), | ||
'project fields explicitly loaded match expected config' | ||
) | ||
|
||
// TODO: since we don't delete icons, this wouldn't match | ||
// const projectIcons = await project1[kDataTypes].icon.getMany() | ||
// st.alike( | ||
// projectIcons.map((icon) => icon.name), | ||
// loadedIcons.map((icon) => icon.name) | ||
// ) | ||
} | ||
) | ||
}) | ||
|
||
test('Managing added projects', async (t) => { | ||
const manager = new MapeoManager({ | ||
rootKey: KeyManager.generateRootKey(), | ||
|
@@ -144,7 +224,7 @@ test('Managing added projects', async (t) => { | |
{ waitForSync: false } | ||
) | ||
|
||
t.test('initial information from listed projects', async (st) => { | ||
await t.test('initial information from listed projects', async (st) => { | ||
const listedProjects = await manager.listProjects() | ||
|
||
st.is(listedProjects.length, 2) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,7 @@ test('config import - presets', async (t) => { | |
let config = await readConfig('./tests/fixtures/config/invalidPreset.zip') | ||
|
||
/* eslint-disable-next-line */ | ||
for (const field of config.presets()) { | ||
for (const preset of config.presets()) { | ||
} | ||
t.is(config.warnings.length, 2, 'we got two errors when reading presets') | ||
t.not( | ||
|
@@ -208,3 +208,35 @@ test('config import - presets', async (t) => { | |
} | ||
t.is(config.warnings.length, 0, `no warnings on the file`) | ||
}) | ||
|
||
test('config import - load default config', async (t) => { | ||
let config = await readConfig('./config/defaultConfig.mapeoconfig') | ||
tomasciccola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.ok(config, 'valid config file') | ||
|
||
let nFields = 0 | ||
/* eslint-disable-next-line */ | ||
for (const field of config.fields()) { | ||
nFields++ | ||
} | ||
t.is(nFields, 2, 'correct number of fields in default config') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I realize that I built the default config using the incorrect repo (this one). I think that if we're removing the default config on a follow-up PR (and having it built as a devdep) then we maybe leave this as is and update the tests on that PR when it actually points to the correct config? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No that would be it, ok to resolve in a follow up |
||
let nIcons = 0 | ||
let nVariants = 0 | ||
/* eslint-disable-next-line */ | ||
for await (const icon of config.icons()) { | ||
nIcons++ | ||
/* eslint-disable-next-line */ | ||
for (let variant of icon.variants) { | ||
nVariants++ | ||
} | ||
} | ||
t.is(nIcons, 41, 'correct number of icons in default config') | ||
t.is(nVariants, 369, 'correct number of icon variants in default config') | ||
|
||
let nPresets = 0 | ||
/* eslint-disable-next-line */ | ||
for (const preset of config.presets()) { | ||
nPresets++ | ||
} | ||
t.is(nPresets, 43, 'correct number of presets in default config') | ||
t.is(config.warnings.length, 0, 'no warnings on config file') | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi, this change is not actually in the scope of this PR, but is related to
datatype.delete
now taking adocId
instead ofversionId
(I went ahead since it was a small change...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggests we were lacking test coverage here. Can you create an issue to create an e2e test for changing config, to ensure that old config is correctly deleted.