Skip to content

Commit

Permalink
test: add more tests to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDecMeetsMore committed Jul 17, 2024
1 parent a08ea16 commit 8bac479
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 68 deletions.
2 changes: 1 addition & 1 deletion scheduler/clients/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "tsc --p ./tsconfig.release.json",
"deploy": "pnpm run build && pnpm publish --no-git-checks",
"test": "jest tests/ -i --verbose"
"test": "jest -i --verbose"
},
"repository": {
"type": "git",
Expand Down
242 changes: 175 additions & 67 deletions scheduler/clients/javascript/tests/integration/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Account, Calendar, INettuClient, NettuClient, User } from "../../lib";
import {
setupAccount,
setupUserClientForAccount,
CREATE_ACCOUNT_CODE,
} from "../helpers/fixtures";
import { readPrivateKey, readPublicKey } from "../helpers/utils";
import { Calendar, INettuClient, User, CalendarEvent } from "../../lib";
import { setupAccount } from "../helpers/fixtures";

// This test suite is testing the specifications for our use cases

Expand All @@ -13,7 +8,10 @@ describe("Integration", () => {
let accountId: string | undefined;

let user1: User | undefined;
let calendar1: Calendar | undefined;
let user1Calendar1: Calendar | undefined;
let user1Calendar1Event1: CalendarEvent | undefined;
let user1Calendar2: Calendar | undefined;
// let user1Calendar2Event1: CalendarEvent | undefined;

beforeAll(async () => {
const account = await setupAccount();
Expand All @@ -22,76 +20,186 @@ describe("Integration", () => {
client = account.client;
});

it("should create a user", async () => {
// TODO: we cannot provide an ID for the user
// For our use case, we would like to provide our own ID
// To be adapted
const res = await client?.user.create();
if (!res?.data) {
throw new Error("User not created");
}
expect(res?.status).toBe(201);

user1 = res.data.user;
});
describe("Basic functionalities", () => {
it("should create a user", async () => {
// TODO: we cannot provide an ID for the user
// For our use case, we would like to provide our own ID
// To be adapted
const res = await client?.user.create();
if (!res?.data) {
throw new Error("User not created");
}
expect(res?.status).toBe(201);

it("should create a calendar", async () => {
if (!user1) {
throw new Error("No user");
}
const res = await client?.calendar.create(user1.id, {
timezone: "Asia/Tokyo",
user1 = res.data.user;
});
expect(res?.status).toBe(201);

if (!res?.data) {
throw new Error("Calendar not created");
}
it("should create a calendar", async () => {
if (!user1) {
throw new Error("No user");
}
const res = await client?.calendar.create(user1.id, {
timezone: "Asia/Tokyo",
});
expect(res?.status).toBe(201);

calendar1 = res.data?.calendar;
});
if (!res?.data) {
throw new Error("Calendar not created");
}

user1Calendar1 = res.data?.calendar;
});

it("should list the events in the calendar and get an empty array", async () => {
if (!user1Calendar1) {
throw new Error("No calendar");
}
const startTs = 10;
const endTs = 1000 * 60 * 60 * 24 * 4;

const res = await client?.calendar.getEvents(
user1Calendar1.id,
startTs,
endTs
);

expect(res?.status).toBe(200);
expect(res?.data).toBeDefined();
expect(res?.data?.events.length).toBe(0);
});

it("should query freebusy and get no events", async () => {
if (!user1 || !user1Calendar1) {
throw new Error("No user or calendar");
}
const res = await client?.user.freebusy(user1?.id, {
startTs: 10,
endTs: 1000 * 60 * 60 * 24 * 4,
calendarIds: [user1Calendar1.id],
});
if (!res?.data) {
throw new Error("Freebusy not found");
}
expect(res.status).toBe(200);
expect(res.data.busy.length).toBe(0);
});

it("should create one event for the user", async () => {
if (!user1 || !user1Calendar1) {
throw new Error("No user or calendar");
}
const res = await client?.events.create(user1.id, {
calendarId: user1Calendar1.id,
duration: 1000 * 60 * 60,
startTs: 0,
busy: true,
});
expect(res?.status).toBe(201);
user1Calendar1Event1 = res?.data?.event;
});

it("should list the events in the calendar and get one event", async () => {
if (!user1Calendar1) {
throw new Error("No calendar");
}
const startTs = 10;
const endTs = 1000 * 60 * 60 * 24 * 4;

it("should not show any freebusy with no events", async () => {
if (!user1 || !calendar1) {
throw new Error("No user or calendar");
}
const res = await client?.user.freebusy(user1?.id, {
endTs: 1000 * 60 * 60 * 24 * 4,
startTs: 10,
calendarIds: [calendar1.id],
const res = await client?.calendar.getEvents(
user1Calendar1.id,
startTs,
endTs
);

expect(res?.status).toBe(200);
expect(res?.data).toBeDefined();
expect(res?.data?.events.length).toBe(1);
expect(res?.data?.events[0].event.id).toEqual(user1Calendar1Event1?.id);
});

it("should show correct freebusy with a single event in calendar", async () => {
if (!user1 || !user1Calendar1) {
throw new Error("No user or calendar");
}
const res = await client?.user.freebusy(user1.id, {
endTs: 1000 * 60 * 60 * 24 * 4,
startTs: 10,
calendarIds: [user1Calendar1.id],
});
if (!res?.data) {
throw new Error("Freebusy not found");
}
expect(res.data.busy.length).toBe(1);
});
if (!res?.data) {
throw new Error("Freebusy not found");
}
expect(res.status).toBe(200);
expect(res.data.busy.length).toBe(0);
});

it("should create one event for the user", async () => {
if (!user1 || !calendar1) {
throw new Error("No user or calendar");
}
const res = await client?.events.create(user1.id, {
calendarId: calendar1.id,
duration: 1000 * 60 * 60,
startTs: 0,
busy: true,
describe("With 2 calendars", () => {
it("should create a 2nd calendar", async () => {
if (!user1) {
throw new Error("No user");
}
const res = await client?.calendar.create(user1.id, {
timezone: "Asia/Tokyo",
});
expect(res?.status).toBe(201);

if (!res?.data) {
throw new Error("Calendar not created");
}

user1Calendar2 = res.data?.calendar;
});

it("should list the events in the 2nd calendar and get an empty array", async () => {
if (!user1Calendar2) {
throw new Error("No calendar");
}
const startTs = 10;
const endTs = 1000 * 60 * 60 * 24 * 4;

const res = await client?.calendar.getEvents(
user1Calendar2.id,
startTs,
endTs
);

expect(res?.status).toBe(200);
expect(res?.data).toBeDefined();
expect(res?.data?.events.length).toBe(0);
});
expect(res?.status).toBe(201);
});

it("should show correct freebusy with a single event in calendar", async () => {
if (!user1 || !calendar1) {
throw new Error("No user or calendar");
}
const res = await client?.user.freebusy(user1.id, {
endTs: 1000 * 60 * 60 * 24 * 4,
startTs: 10,
calendarIds: [calendar1.id],
describe("With multiple users", () => {
let user2: User | undefined;
let calendar2: Calendar | undefined;

beforeAll(async () => {
const res = await client?.user.create();
if (!res?.data) {
throw new Error("User not created");
}
user2 = res.data.user;

const res2 = await client?.calendar.create(user2.id, {
timezone: "Asia/Tokyo",
});
if (!res2?.data) {
throw new Error("Calendar not created");
}
calendar2 = res2.data.calendar;

if (!user2 || !calendar2) {
throw new Error("No user or calendar");
}
const resEvent = await client?.events.create(user2.id, {
calendarId: calendar2.id,
duration: 1000 * 60 * 60,
startTs: 1000 * 60 * 60,
busy: true,
});
expect(resEvent?.status).toBe(201);
});
if (!res?.data) {
throw new Error("Freebusy not found");
}
expect(res.data.busy.length).toBe(1);

it.todo("should show correct freebusy for both users (admin)");
});
});

0 comments on commit 8bac479

Please sign in to comment.