Skip to content

Commit

Permalink
Fix Core migration integration tests
Browse files Browse the repository at this point in the history
The existing tests incorrectly asserted an object's `migrationVersion`
solely based on the registered type's `migration` field; in reality, the
`convertToMultiNamespaceTypeVersion` field is also used when determining
an object's `migrationVersion`. This commit simply updates the test to
reflect that.
  • Loading branch information
jportner committed Sep 9, 2021
1 parent 471e0ef commit 11c905d
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,23 @@ describe('migration v2', () => {
.getTypeRegistry()
.getAllTypes()
.reduce((versionMap, type) => {
if (type.migrations) {
const migrationsMap =
typeof type.migrations === 'function' ? type.migrations() : type.migrations;
const highestVersion = Object.keys(migrationsMap).sort(Semver.compare).reverse()[0];
const { name, migrations, convertToMultiNamespaceTypeVersion } = type;
if (migrations || convertToMultiNamespaceTypeVersion) {
const migrationsMap = typeof migrations === 'function' ? migrations() : migrations;
const migrationsKeys = migrationsMap ? Object.keys(migrationsMap) : [];
if (convertToMultiNamespaceTypeVersion) {
// Setting this option registers a conversion migration that is reflected in the object's `migrationVersions` field
migrationsKeys.push(convertToMultiNamespaceTypeVersion);
}
const highestVersion = migrationsKeys.sort(Semver.compare).reverse()[0];
return {
...versionMap,
[type.name]: highestVersion,
[name]: highestVersion,
};
} else {
return {
...versionMap,
[type.name]: undefined,
[name]: undefined,
};
}
}, {} as Record<string, string | undefined>);
Expand Down

0 comments on commit 11c905d

Please sign in to comment.