Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmuniz1994 committed Oct 27, 2023
1 parent fcb7dd3 commit 7bb6a70
Showing 1 changed file with 58 additions and 15 deletions.
73 changes: 58 additions & 15 deletions src/hooks/useRedirectionRule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,29 @@ describe("getRedirectionRule: / (auth)", () => {

describe("getRedirectionRule: /create", () => {
it("when not authenticated, then go back to root for login", () => {
const result = getRedirectionRule({ path: "/create", hasAuth: false }, {});
const result = getRedirectionRule(
{ path: "/create", hasAuth: false, isSessionBlocked: false },
{}
);
expect(result).toBe("/");
});

it("when authenticated, stay here for device testing and call creation", () => {
const result = getRedirectionRule({ path: "/create", hasAuth: true }, {});
const result = getRedirectionRule(
{ path: "/create", hasAuth: true, isSessionBlocked: false },
{}
);
expect(result).toBe("");
});

it("when authenticated and has ongoing call, go to its page", () => {
const result = getRedirectionRule(
{ path: "/create", hasAuth: true, ongoingCall: "123-321" },
{
path: "/create",
hasAuth: true,
ongoingCall: "123-321",
isSessionBlocked: false,
},
{}
);
expect(result).toBe("/p2p-call/123-321");
Expand All @@ -51,33 +62,44 @@ describe("getRedirectionRule: /create", () => {
describe("getRedirectionRule: /join", () => {
it("when authenticated and provided call uid, then stay here for device testing", () => {
const result = getRedirectionRule(
{ path: "/join", hasAuth: true },
{ path: "/join", hasAuth: true, isSessionBlocked: false },
{ callUid: "123-321" }
);
expect(result).toBe("");
});

it("when not authenticated but provided call uid, then go authenticate", () => {
const result = getRedirectionRule(
{ path: "/join", hasAuth: false },
{ path: "/join", hasAuth: false, isSessionBlocked: false },
{ callUid: "123-321" }
);
expect(result).toBe("/?joining=123-321");
});

it("when not authenticated nor provided call uid, then start reset entire flow (came here by mistake?)", () => {
const result = getRedirectionRule({ path: "/join", hasAuth: false }, {});
const result = getRedirectionRule(
{ path: "/join", hasAuth: false, isSessionBlocked: false },
{}
);
expect(result).toBe("/");
});

it("when authenticated and didnt provide call uid, then stay to manually type it", () => {
const result = getRedirectionRule({ path: "/join", hasAuth: true }, {});
const result = getRedirectionRule(
{ path: "/join", hasAuth: true, isSessionBlocked: false },
{}
);
expect(result).toBe("");
});

it("when authenticated and has pending call, go to pending user page", () => {
const result = getRedirectionRule(
{ path: "/join", hasAuth: true, pendingCall: "123-call-321" },
{
path: "/join",
hasAuth: true,
pendingCall: "123-call-321",
isSessionBlocked: false,
},
{}
);
expect(result).toBe("/pending");
Expand All @@ -87,43 +109,64 @@ describe("getRedirectionRule: /join", () => {
describe("getRedirectionRule: /join", () => {
it("if has pending call, stay waiting", () => {
const result = getRedirectionRule(
{ path: "/pending", hasAuth: true, pendingCall: "123-call-321" },
{
path: "/pending",
hasAuth: true,
pendingCall: "123-call-321",
isSessionBlocked: false,
},
{}
);
expect(result).toBe("");
});

it("if has ongoing call, go for it", () => {
const result = getRedirectionRule(
{ path: "/pending", hasAuth: true, ongoingCall: "123-call-321" },
{
path: "/pending",
hasAuth: true,
ongoingCall: "123-call-321",
isSessionBlocked: false,
},
{}
);
expect(result).toBe("/p2p-call/123-call-321");
});

it("if has none, reset navigation flow", () => {
const result = getRedirectionRule({ path: "/pending", hasAuth: true }, {});
const result = getRedirectionRule(
{ path: "/pending", hasAuth: true, isSessionBlocked: false },
{}
);
expect(result).toBe("/");
});

it("when not authenticated, reset navigation flow", () => {
const result = getRedirectionRule({ path: "/pending", hasAuth: false }, {});
const result = getRedirectionRule(
{ path: "/pending", hasAuth: false, isSessionBlocked: false },
{}
);
expect(result).toBe("/");
});
});

describe("getRedirectionRule: /p2p-call", () => {
it("when authenticated with ongoing call, then stay here", () => {
const result = getRedirectionRule(
{ path: "/p2p-call/123-321", hasAuth: true, ongoingCall: "123-321" },
{
path: "/p2p-call/123-321",
hasAuth: true,
ongoingCall: "123-321",
isSessionBlocked: false,
},
{}
);
expect(result).toBe("");
});

it("when authenticated without ongoing call, go to a page saying good bye", () => {
const result = getRedirectionRule(
{ path: "/p2p-call/123-321", hasAuth: true },
{ path: "/p2p-call/123-321", hasAuth: true, isSessionBlocked: false },
{}
);
// expect(result).toBe("/left");
Expand All @@ -133,7 +176,7 @@ describe("getRedirectionRule: /p2p-call", () => {
it("when not authenticated, be forced to reset flow", () => {
// TODO: retrieve attempt call uid and convert into "/?joining=" flow
const result = getRedirectionRule(
{ path: "/p2p-call/123-321", hasAuth: false },
{ path: "/p2p-call/123-321", hasAuth: false, isSessionBlocked: false },
{}
);
expect(result).toBe("/");
Expand Down

0 comments on commit 7bb6a70

Please sign in to comment.