Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed failing test
  • Loading branch information
temi committed Sep 17, 2023
1 parent a74956e commit 81eba48
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions src/test/js/spec/EntitiesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,43 +166,43 @@ describe("Entities", function () {

it("should get activities for a project activity", async function () {
var activities = [
{activityId: "1", projectActivityId: "a", lastUpdated: new Date(2018, 1, 1)},
{activityId: "2", projectActivityId: "a", lastUpdated: new Date(2019, 1, 1)},
{activityId: "3", projectActivityId: "a", lastUpdated: new Date(2016, 1, 1)},
{activityId: "4", projectActivityId: "b", lastUpdated: new Date(2015, 1, 1)},
{activityId: "5", projectActivityId: "b", lastUpdated: new Date(2020, 1, 1)}
{activityId: 1, projectActivityId: "a", lastUpdated: new Date(2018, 1, 1)},
{activityId: 2, projectActivityId: "a", lastUpdated: new Date(2019, 1, 1)},
{activityId: 3, projectActivityId: "a", lastUpdated: new Date(2016, 1, 1)},
{activityId: 4, projectActivityId: "b", lastUpdated: new Date(2015, 1, 1)},
{activityId: 5, projectActivityId: "b", lastUpdated: new Date(2020, 1, 1)}
];

var result = await new Promise((resolve, reject) => {
entities.saveActivities(activities).then(resolve, reject);
});

result = await new Promise((resolve, reject) => {
entities.getActivitiesForProjectActivity("a", 2, 0, "lastUpdated", "DESC").then(resolve, reject);
entities.getActivitiesForProjectActivity("a", 2, 0, "activityId", "DESC").then(resolve, reject);
});

var activityData = result.data;
expect(activityData.activities.length).toBe(2);
expect(activityData.activities[0].activityId).toBe("2");
expect(activityData.activities[1].activityId).toBe("1");
expect(activityData.activities[0].activityId).toBe(3);
expect(activityData.activities[1].activityId).toBe(2);
expect(activityData.total).toBe(3);

result = await new Promise((resolve, reject) => {
entities.getActivitiesForProjectActivity("b", 2, 0, "lastUpdated", "ASC").then(resolve, reject);
entities.getActivitiesForProjectActivity("b", 2, 0, "activityId", "ASC").then(resolve, reject);
});

activityData = result.data;
expect(activityData.activities.length).toBe(2);
expect(activityData.activities[0].activityId).toBe("4");
expect(activityData.activities[1].activityId).toBe("5");
expect(activityData.activities[0].activityId).toBe(4);
expect(activityData.activities[1].activityId).toBe(5);
expect(activityData.total).toBe(2);

result = await new Promise((resolve, reject) => {
entities.deleteTable('activity').then(resolve, reject);
});

result = await new Promise((resolve, reject) => {
entities.getActivitiesForProjectActivity("b", 2, 0, "lastUpdated", "ASC").then(resolve, reject);
entities.getActivitiesForProjectActivity("b", 2, 0, "activityId", "ASC").then(resolve, reject);
})

activityData = result.data;
Expand All @@ -212,43 +212,43 @@ describe("Entities", function () {

it("should get activities for a project", async function () {
var activities = [
{activityId: "1", projectActivityId: "a", projectId: "n", lastUpdated: new Date(2018, 1, 1)},
{activityId: "2", projectActivityId: "a", projectId: "n", lastUpdated: new Date(2019, 1, 1)},
{activityId: "3", projectActivityId: "a", projectId: "n", lastUpdated: new Date(2016, 1, 1)},
{activityId: "4", projectActivityId: "b", projectId: "m", lastUpdated: new Date(2015, 1, 1)},
{activityId: "5", projectActivityId: "b", projectId: "m", lastUpdated: new Date(2020, 1, 1)}
{activityId: 1, projectActivityId: "a", projectId: "n", lastUpdated: new Date(2018, 1, 1)},
{activityId: 2, projectActivityId: "a", projectId: "n", lastUpdated: new Date(2019, 1, 1)},
{activityId: 3, projectActivityId: "a", projectId: "n", lastUpdated: new Date(2016, 1, 1)},
{activityId: 4, projectActivityId: "b", projectId: "m", lastUpdated: new Date(2015, 1, 1)},
{activityId: 5, projectActivityId: "b", projectId: "m", lastUpdated: new Date(2020, 1, 1)}
];

var result = await new Promise((resolve, reject) => {
entities.saveActivities(activities).then(resolve, reject);
});

result = await new Promise((resolve, reject) => {
entities.offlineGetActivitiesForProject("n", 2, 0, "lastUpdated", "DESC").then(resolve, reject);
entities.offlineGetActivitiesForProject("n", 2, 0, "activityId", "DESC").then(resolve, reject);
});

var activityData = result.data;
expect(activityData.activities.length).toBe(2);
expect(activityData.activities[0].activityId).toBe("2");
expect(activityData.activities[1].activityId).toBe("1");
expect(activityData.activities[0].activityId).toBe(3);
expect(activityData.activities[1].activityId).toBe(2);
expect(activityData.total).toBe(3);

result = await new Promise((resolve, reject) => {
entities.offlineGetActivitiesForProject("m", 2, 0, "lastUpdated", "ASC").then(resolve, reject);
entities.offlineGetActivitiesForProject("m", 2, 0, "activityId", "ASC").then(resolve, reject);
});

activityData = result.data;
expect(activityData.activities.length).toBe(2);
expect(activityData.activities[0].activityId).toBe("4");
expect(activityData.activities[1].activityId).toBe("5");
expect(activityData.activities[0].activityId).toBe(4);
expect(activityData.activities[1].activityId).toBe(5);
expect(activityData.total).toBe(2);

result = await new Promise((resolve, reject) => {
entities.deleteTable("activity").then(resolve, reject);
});

result = await new Promise((resolve, reject) => {
entities.getActivitiesForProjectActivity("b", 2, 0, "lastUpdated", "ASC").then(resolve, reject);
entities.getActivitiesForProjectActivity("b", 2, 0, "activityId", "ASC").then(resolve, reject);
})

activityData = result.data;
Expand All @@ -259,44 +259,43 @@ describe("Entities", function () {

it("should get all activities", async function () {
var activities = [
{activityId: "1", projectActivityId: "a", projectId: "n", lastUpdated: new Date(2018, 1, 1)},
{activityId: "2", projectActivityId: "a", projectId: "n", lastUpdated: new Date(2019, 1, 1)},
{activityId: "3", projectActivityId: "a", projectId: "n", lastUpdated: new Date(2016, 1, 1)},
{activityId: "4", projectActivityId: "b", projectId: "m", lastUpdated: new Date(2015, 1, 1)},
{activityId: "5", projectActivityId: "b", projectId: "m", lastUpdated: new Date(2020, 1, 1)}
{activityId: 1, projectActivityId: "a", projectId: "n", lastUpdated: new Date(2018, 1, 1)},
{activityId: 2, projectActivityId: "a", projectId: "n", lastUpdated: new Date(2019, 1, 1)},
{activityId: 3, projectActivityId: "a", projectId: "n", lastUpdated: new Date(2016, 1, 1)},
{activityId: 4, projectActivityId: "b", projectId: "m", lastUpdated: new Date(2015, 1, 1)},
{activityId: 5, projectActivityId: "b", projectId: "m", lastUpdated: new Date(2020, 1, 1)}
];

var result = await new Promise((resolve, reject) => {
entities.saveActivities(activities).then(resolve, reject);
});

result = await new Promise((resolve, reject) => {
entities.offlineGetAllActivities(10, 0, "lastUpdated", "DESC").then(resolve, reject);
entities.offlineGetAllActivities(10, 0, "activityId", "DESC").then(resolve, reject);
});

var activityData = result.data;
expect(activityData.activities.length).toBe(5);
expect(activityData.activities[0].activityId).toBe("5");
expect(activityData.activities[1].activityId).toBe("2");
console.log(JSON.stringify(activityData));
expect(activityData.activities[0].activityId).toBe(5);
expect(activityData.activities[1].activityId).toBe(4);
expect(activityData.total).toBe(5);

result = await new Promise((resolve, reject) => {
entities.offlineGetAllActivities(2, 0, "lastUpdated", "ASC").then(resolve, reject);
entities.offlineGetAllActivities(2, 0, "activityId", "ASC").then(resolve, reject);
});

activityData = result.data;
expect(activityData.activities.length).toBe(2);
expect(activityData.activities[0].activityId).toBe("4");
expect(activityData.activities[1].activityId).toBe("3");
expect(activityData.activities[0].activityId).toBe(1);
expect(activityData.activities[1].activityId).toBe(2);
expect(activityData.total).toBe(5);

await new Promise((resolve, reject) => {
entities.deleteTable("activity").then(resolve, reject);
});

result = await new Promise((resolve, reject) => {
entities.offlineGetAllActivities(2, 0, "lastUpdated", "ASC").then(resolve, reject);
entities.offlineGetAllActivities(2, 0, "activityId", "ASC").then(resolve, reject);
})

activityData = result.data;
Expand Down

0 comments on commit 81eba48

Please sign in to comment.