Skip to content
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

Add ID conversion check in CharacterFactory #551

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/domains/character/CharacterFactory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { CharacterFactory } from "./CharacterFactory";
import { DefaultTemplates } from "./DefaultTemplates";
import { ComplexCharacter } from "./mocks/ComplexCharacter";
import { DuplicateIds } from "./mocks/DuplicateIds";
import { Warden } from "./mocks/WardenLeMagane";
import { IV1Character } from "./types";
import { ICharacter, IV1Character } from "./types";

Check warning on line 7 in lib/domains/character/CharacterFactory.test.tsx

View workflow job for this annotation

GitHub Actions / build

'ICharacter' is defined but never used

describe("CharacterFactory.migrate", () => {
describe("v1", () => {
Expand Down Expand Up @@ -691,4 +692,27 @@
});
});
});

it("should handle duplicate id imports", () => {
const result = CharacterFactory.makeFromJson(DuplicateIds);

const ids = [result.id];

for (const page of result.pages) {
ids.push(page.id);
for (const row of page.rows) {
for (const column of row.columns) {
for (const section of column.sections) {
ids.push(section.id);
for (const block of section.blocks) {
ids.push(block.id);
}
}
}
}
}

// This should check for duplicates
expect(new Set(ids).size).toEqual(ids.length);
});
});
2 changes: 1 addition & 1 deletion lib/domains/character/CharacterFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const CharacterFactory = {
default: undefined,
};
const migratedSheet = this.migrate(newSheet);
return migratedSheet;
return CharacterFactory.resetAllIds(migratedSheet);
},
migrate(character: any): ICharacter {
try {
Expand Down
Loading
Loading