Skip to content

Commit

Permalink
FIX: links and icons theme setting migrations to handle blank str…
Browse files Browse the repository at this point in the history
…ing (#50)

If the old theme setting value is set to a blank string, we will end up
not migrating it and thus cause an error to be raised.
  • Loading branch information
tgxworld authored Aug 1, 2024
1 parent f458dc9 commit 9e7c224
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion migrations/settings/0001-migrate-links-setting.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function migrate(settings) {
const oldSetting = settings.get("links");

if (oldSetting) {
if (typeof oldSetting === "string") {
const newLinks = [];

oldSetting.split("|").forEach((link) => {
Expand Down
2 changes: 1 addition & 1 deletion migrations/settings/0002-migrate-icons-setting.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function migrate(settings) {
const oldSetting = settings.get("icons");

if (oldSetting) {
if (typeof oldSetting === "string") {
const newIcons = [];

oldSetting.split("|").map((link) => {
Expand Down
16 changes: 16 additions & 0 deletions test/unit/migrations/settings/0001-migrate-links-setting-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import migrate from "../../../../migrations/settings/0001-migrate-links-setting"
module(
"Brand Header | Unit | Migrations | Settings | 0001-migrate-links-setting",
function () {
test("migrate when old setting is a blank string", function (assert) {
const settings = new Map(Object.entries({ links: "" }));
const result = migrate(settings);

const expectedResult = new Map(
Object.entries({
links: [],
})
);

assert.deepEqual(
Object.fromEntries(result.entries()),
Object.fromEntries(expectedResult.entries())
);
});

test("migrate when old setting is of an invalid format", function (assert) {
const settings = new Map(
Object.entries({
Expand Down
16 changes: 16 additions & 0 deletions test/unit/migrations/settings/0002-migrate-icons-setting-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import migrate from "../../../../migrations/settings/0002-migrate-icons-setting"
module(
"Brand Header | Unit | Migrations | Settings | 0002-migrate-icons-setting",
function () {
test("migrate when old setting is a blank string", function (assert) {
const settings = new Map(Object.entries({ icons: "" }));
const result = migrate(settings);

const expectedResult = new Map(
Object.entries({
icons: [],
})
);

assert.deepEqual(
Object.fromEntries(result.entries()),
Object.fromEntries(expectedResult.entries())
);
});

test("migrate when old setting value is of an invalid format", function (assert) {
const settings = new Map(
Object.entries({
Expand Down

0 comments on commit 9e7c224

Please sign in to comment.