Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/web/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ export type PartnerProps = z.infer<typeof PartnerSchema> & {
};

export type PartnerUserProps = z.infer<typeof partnerUserSchema>;

export type PartnerProfileCustomerProps = z.infer<
typeof PartnerProfileCustomerSchema
>;
Expand Down Expand Up @@ -480,7 +479,6 @@ export type ProgramApplicationFormDataWithValues = z.infer<
export type ProgramApplicationFormFieldWithValues = z.infer<
typeof programApplicationFormFieldWithValuesSchema
>;

export type ProgramEnrollmentProps = z.infer<typeof ProgramEnrollmentSchema>;

export type PayoutsCount = {
Expand Down
162 changes: 162 additions & 0 deletions apps/web/tests/partner-groups/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { generateRandomName } from "@/lib/names";
import {
GroupExtendedProps,
GroupProps,
GroupWithProgramProps,
} from "@/lib/types";
import { GroupSchema } from "@/lib/zod/schemas/groups";
import { RESOURCE_COLORS } from "@/ui/colors";
import { randomValue } from "@dub/utils";
import slugify from "@sindresorhus/slugify";
import { describe, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";

const expectedGroup: Partial<GroupProps> = {
id: expect.any(String),
name: expect.any(String),
slug: expect.any(String),
color: expect.any(String),
clickReward: null,
leadReward: null,
saleReward: null,
discount: null,
maxPartnerLinks: 10,
linkStructure: "short",
additionalLinks: expect.any(Array),
};

describe.sequential("/groups/**", async () => {
const h = new IntegrationHarness();
const { http } = await h.init();

let group: GroupProps;

test("POST /groups - create group", async () => {
const groupName = generateRandomName();

const newGroup = {
name: `E2E-${groupName}`,
slug: slugify(groupName),
color: randomValue(RESOURCE_COLORS),
};

const { status, data } = await http.post<GroupProps>({
path: "/groups",
body: newGroup,
});

expect(status).toEqual(201);
expect(() => GroupSchema.parse(data)).not.toThrow();
expect(data).toStrictEqual({
...expectedGroup,
...newGroup,
});

group = data;
});

test("GET /groups/[groupId] - fetch single group", async () => {
const { status, data } = await http.get<GroupWithProgramProps>({
path: `/groups/${group.id}`,
});

const {
applicationFormData,
applicationFormPublishedAt,
landerData,
landerPublishedAt,
program,
...fetchedGroup
} = data;

expect(status).toEqual(200);
expect(fetchedGroup).toStrictEqual({
...group,
utmTemplate: null,
});
});

test("PATCH /groups/[groupId] - update group", async () => {
const toUpdate = {
name: `E2E-${generateRandomName()}`,
color: randomValue(RESOURCE_COLORS),
maxPartnerLinks: 5,
linkStructure: "query",
additionalLinks: [
{
domain: "example.com",
path: "",
validationMode: "domain",
},
{
domain: "acme.com",
path: "/products",
validationMode: "exact",
},
],
};

const { status, data: updatedGroup } = await http.patch<GroupProps>({
path: `/groups/${group.id}`,
body: toUpdate,
});

expect(status).toEqual(200);
expect(updatedGroup).toStrictEqual({
...group,
...toUpdate,
});

group = updatedGroup;
});

test("GET /groups - fetch all groups", async () => {
const { status, data: groups } = await http.get<GroupExtendedProps[]>({
path: "/groups",
});

expect(status).toEqual(200);
expect(Array.isArray(groups)).toBe(true);
expect(groups.length).toBeGreaterThan(0);

const fetchedGroup = groups.find((g) => g.id === group.id);

expect(fetchedGroup).toStrictEqual({
id: group.id,
name: group.name,
slug: group.slug,
color: group.color,
additionalLinks: group.additionalLinks,
maxPartnerLinks: group.maxPartnerLinks,
linkStructure: group.linkStructure,
totalPartners: 0,
totalClicks: 0,
totalLeads: 0,
totalSales: 0,
totalSaleAmount: 0,
totalConversions: 0,
totalCommissions: 0,
netRevenue: 0,
});
});

test("DELETE /groups/[groupId] - delete group", async () => {
const { status, data } = await http.delete<{ id: string }>({
path: `/groups/${group.id}`,
});

expect(status).toEqual(200);
expect(data).toStrictEqual({
id: group.id,
});

const { status: getStatus } = await http.get({
path: `/groups/${group.id}`,
});

expect(getStatus).toEqual(404);
});
});

// TODO(kiran):
// Add more test cases to test the default link creation and group move
4 changes: 2 additions & 2 deletions apps/web/ui/modals/delete-group-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const DeleteGroupModal = ({
<p className="block text-sm text-neutral-500">
To verify, type{" "}
<span className="font-medium text-neutral-700">
Delete group
confirm delete group
</span>{" "}
below
</p>
Expand All @@ -113,7 +113,7 @@ const DeleteGroupModal = ({
className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
aria-invalid="true"
autoFocus={!isMobile}
pattern="Delete group"
pattern="confirm delete group"
/>
</div>
</div>
Expand Down