feat(frontend): list the company invitations in the employer cabinet
This commit is contained in:
1 parent
84454116f2
commit
d8abaae85b
23 files changed
+1349
-222
No files matched your search
@@ -0,0 +1,110 @@
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { setupServer } from "msw/node";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ApiRequestError, invalidResponseCode } from "../../../shared/api";
|
||||
import { invitationListPageSize, listInvitationsOfOrganization } from "./organization-invitations";
|
||||
|
||||
const organizationId = "0199b4f2-7c1e-7d3a-9f00-aabbccddee01";
|
||||
const base = `http://localhost/api/v1/organizations/${organizationId}/invitations`;
|
||||
|
||||
const server = setupServer();
|
||||
beforeAll(() => server.listen({ onUnhandledFrame: "error" }));
|
||||
beforeEach(() => {
|
||||
// The browser client uses same-origin paths; Node needs an origin.
|
||||
const realFetch = globalThis.fetch;
|
||||
vi.stubGlobal("fetch", (input: string, init?: RequestInit) =>
|
||||
realFetch(new URL(input, "http://localhost"), init),
|
||||
);
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
server.resetHandlers();
|
||||
});
|
||||
afterAll(() => server.close());
|
||||
|
||||
const summary = {
|
||||
id: "0199b4f2-7c1e-7d3a-9f00-aabbccdd3301",
|
||||
candidate_handle: `cv1_${"A".repeat(43)}`,
|
||||
need: null,
|
||||
state: "delivered",
|
||||
expiry_reason: null,
|
||||
version: 2,
|
||||
terms_version: 1,
|
||||
role_title: "Middle Go-разработчик",
|
||||
salary: {
|
||||
salary_from: 100000,
|
||||
salary_to: 140000,
|
||||
currency: "RUB",
|
||||
period: "month",
|
||||
tax_basis: "net",
|
||||
},
|
||||
response_deadline_at: "2099-10-16T10:00:00Z",
|
||||
contact_access: { status: "not_granted", fields: [] },
|
||||
created_at: "2026-10-09T10:00:00Z",
|
||||
updated_at: "2026-10-09T10:05:00Z",
|
||||
};
|
||||
|
||||
describe("organization invitation list transport", () => {
|
||||
it("reads a page with the page size and the cursor and parses it with the contract", async () => {
|
||||
const seen: { query: URLSearchParams | null } = { query: null };
|
||||
server.use(
|
||||
http.get(base, ({ request }) => {
|
||||
seen.query = new URL(request.url).searchParams;
|
||||
return HttpResponse.json({
|
||||
items: [summary],
|
||||
page: { has_more: true, next_cursor: "next-1" },
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
const list = await listInvitationsOfOrganization(organizationId, { cursor: "first-1" });
|
||||
|
||||
expect(seen.query?.get("limit")).toBe(String(invitationListPageSize));
|
||||
expect(seen.query?.get("cursor")).toBe("first-1");
|
||||
expect(list.items[0]?.role_title).toBe("Middle Go-разработчик");
|
||||
expect(list.page).toEqual({ has_more: true, next_cursor: "next-1" });
|
||||
});
|
||||
|
||||
it("sends no cursor for the first page", async () => {
|
||||
const seen: { query: URLSearchParams | null } = { query: null };
|
||||
server.use(
|
||||
http.get(base, ({ request }) => {
|
||||
seen.query = new URL(request.url).searchParams;
|
||||
return HttpResponse.json({ items: [], page: { has_more: false, next_cursor: null } });
|
||||
}),
|
||||
);
|
||||
|
||||
await listInvitationsOfOrganization(organizationId);
|
||||
|
||||
expect(seen.query?.has("cursor")).toBe(false);
|
||||
});
|
||||
|
||||
it("refuses a body that does not match the contract instead of listing it", async () => {
|
||||
server.use(http.get(base, () => HttpResponse.json({ items: [{ id: "not-an-invitation" }] })));
|
||||
|
||||
const failure = await listInvitationsOfOrganization(organizationId).catch(
|
||||
(error: unknown) => error,
|
||||
);
|
||||
|
||||
expect(failure).toBeInstanceOf(ApiRequestError);
|
||||
expect((failure as ApiRequestError).code).toBe(invalidResponseCode);
|
||||
});
|
||||
|
||||
it("surfaces an access refusal with its status", async () => {
|
||||
server.use(
|
||||
http.get(base, () =>
|
||||
HttpResponse.json(
|
||||
{ type: "about:blank", title: "Forbidden", status: 403, code: "forbidden" },
|
||||
{ status: 403, headers: { "Content-Type": "application/problem+json" } },
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const failure = await listInvitationsOfOrganization(organizationId).catch(
|
||||
(error: unknown) => error,
|
||||
);
|
||||
|
||||
expect(failure).toBeInstanceOf(ApiRequestError);
|
||||
expect((failure as ApiRequestError).status).toBe(403);
|
||||
});
|
||||
});
|
||||
@@ -4,15 +4,19 @@ import {
|
||||
getGetOrganizationInvitationContactsQueryKey,
|
||||
getGetOrganizationInvitationQueryKey,
|
||||
getOrganizationInvitation,
|
||||
getListOrganizationInvitationsQueryKey,
|
||||
getOrganizationInvitationContacts,
|
||||
listOrganizationInvitations,
|
||||
sendOrganizationInvitation,
|
||||
updateOrganizationInvitation,
|
||||
} from "../../../shared/api/endpoints/invitation/invitation";
|
||||
import {
|
||||
ContactDisclosure as contactDisclosureSchema,
|
||||
OrganizationInvitation as organizationInvitationSchema,
|
||||
OrganizationInvitationList as organizationInvitationListSchema,
|
||||
type ContactDisclosure,
|
||||
type OrganizationInvitation,
|
||||
type OrganizationInvitationList,
|
||||
type OrganizationInvitationCreate,
|
||||
type OrganizationInvitationUpdate,
|
||||
} from "../../../shared/api/schemas";
|
||||
@@ -36,6 +40,12 @@ function parseInvitation(value: unknown): OrganizationInvitation {
|
||||
return parsed.data;
|
||||
}
|
||||
|
||||
function parseInvitationList(value: unknown): OrganizationInvitationList {
|
||||
const parsed = organizationInvitationListSchema.safeParse(value);
|
||||
if (!parsed.success) throw invalidResponse();
|
||||
return parsed.data;
|
||||
}
|
||||
|
||||
type CommandOptions = {
|
||||
organizationId: string;
|
||||
csrfToken: string;
|
||||
@@ -93,6 +103,31 @@ export async function sendInvitationDraft(
|
||||
);
|
||||
}
|
||||
|
||||
/** Page size of the organization's invitation list. */
|
||||
export const invitationListPageSize = 20;
|
||||
|
||||
/**
|
||||
* Reads one page of the organization's invitations, drafts included, newest
|
||||
* first. The cursor comes only from the previous page. The summaries name a
|
||||
* candidate by the opaque handle alone and hold no contact value.
|
||||
*/
|
||||
export async function listInvitationsOfOrganization(
|
||||
organizationId: string,
|
||||
options: { cursor?: string | undefined; signal?: AbortSignal | undefined } = {},
|
||||
): Promise<OrganizationInvitationList> {
|
||||
const params = {
|
||||
limit: invitationListPageSize,
|
||||
...(options.cursor === undefined ? {} : { cursor: options.cursor }),
|
||||
};
|
||||
return parseInvitationList(
|
||||
await listOrganizationInvitations(
|
||||
organizationId,
|
||||
params,
|
||||
options.signal ? { signal: options.signal } : {},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** Reads one invitation of the organization and checks it against the contract. */
|
||||
export async function readOrganizationInvitation(
|
||||
organizationId: string,
|
||||
@@ -123,6 +158,12 @@ export async function readInvitationContacts(
|
||||
|
||||
/** Invitation reads stay separate for each signed-in account. */
|
||||
export const invitationQueryKeys = {
|
||||
/** Every page of the organization's invitation list for one account. */
|
||||
list: (accountId: string, organizationId: string) =>
|
||||
[
|
||||
...getListOrganizationInvitationsQueryKey(organizationId, { limit: invitationListPageSize }),
|
||||
accountId,
|
||||
] as const,
|
||||
detail: (accountId: string, organizationId: string, invitationId: string) =>
|
||||
[...getGetOrganizationInvitationQueryKey(organizationId, invitationId), accountId] as const,
|
||||
contacts: (accountId: string, organizationId: string, invitationId: string) =>
|
||||
|
||||
Reference in new issue
Block a user