Skip to content

Commit

Permalink
add compliments_file tests to e2e, fix module for interval timer stil…
Browse files Browse the repository at this point in the history
…l running
  • Loading branch information
sdetweil committed Nov 15, 2024
1 parent 9be5535 commit 98ed468
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
17 changes: 13 additions & 4 deletions modules/default/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ Module.register("compliments", {
if ((this.config.remoteFileRefreshInterval >= this.refreshMinimumDelay) || window.mmTestMode === "true") {
setInterval(async () => {
const response = await this.loadComplimentFile();
this.compliments_new = JSON.parse(response);
if (response) {
this.compliments_new = JSON.parse(response);
}
else {
Log.error(`${this.name} remoteFile refresh failed`);
}
},
this.config.remoteFileRefreshInterval);
} else {
Expand Down Expand Up @@ -204,10 +209,14 @@ Module.register("compliments", {
// we need to force the server to not give us the cached result
// create an extra property (ignored by the server handler) just so the url string is different
// that will never be the same, using the ms value of date
if (this.config.remoteFileRefreshInterval !== 0) this.urlSuffix = `?dummy=${Date.now()}`;
if (isRemote && this.config.remoteFileRefreshInterval !== 0) this.urlSuffix = `?dummy=${Date.now()}`;
//
const response = await fetch(url + this.urlSuffix);
return await response.text();
try {
const response = await fetch(url + this.urlSuffix);
return await response.text();
} catch (error) {
Log.info(`${this.name} fetch failed error=`, error);
}
},

/**
Expand Down
33 changes: 33 additions & 0 deletions tests/e2e/modules/compliments_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,37 @@ describe("Compliments module", () => {
});
});
});

describe("Feature remote compliments file", () => {
describe("get list from remote file", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js");
await helpers.getDocument();
});
it("shows 'Remote compliment file works!' as only anytime list set", async () => {
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js", "01 Jan 2022 10:00:00 GMT");
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
});
// afterAll(async () =>{
// await helpers.stopApplication()
// });
});

describe("get list from remote file w update", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js");
await helpers.getDocument();
});
it("shows 'test in morning' as test time set to 10am", async () => {
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js", "01 Jan 2022 10:00:00 GMT");
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
await new Promise((r) => setTimeout(r, 10000));
await expect(doTest(["test in morning"])).resolves.toBe(true);
});
// afterAll(async () =>{
// await helpers.stopApplication()
// });
});
});

});
2 changes: 1 addition & 1 deletion tests/electron/modules/compliments_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("Compliments module", () => {
});
});
describe("get updated list from remote file", () => {
it("shows 'test in morning' as test time set to 10am", async () => {
it("shows 'test in morning'", async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js", "01 Jan 2022 10:00:00 GMT");
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
await new Promise((r) => setTimeout(r, 10000));
Expand Down
4 changes: 1 addition & 3 deletions tests/mocks/compliments_file.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"morning": ["test in morning"],
"afternoon": ["test in afternoon"],
"evening": ["test in evening"]
"anytime": ["test in morning"]
}

0 comments on commit 98ed468

Please sign in to comment.