Skip to content

Commit 22a65ca

Browse files
committed
test: update unit and e2e tests to match function updates
1 parent 0e3ecb5 commit 22a65ca

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

server/events/event.controller.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ describe("EventsController (Unit)", () => {
9898
});
9999
});
100100

101+
describe("createEventPage", () => {
102+
it("should render /event-create with parsed query, namespace and site key", async () => {
103+
const req = {
104+
url: "/event/create?foo=bar",
105+
params: { namespace: "main" },
106+
};
107+
const res = {};
108+
109+
await controller.createEventPage(req as any, res as any);
110+
111+
expect(mockConfigService.get).toHaveBeenCalledWith("recaptcha_sitekey");
112+
expect(mockViewService.render).toHaveBeenCalledWith(
113+
req,
114+
res,
115+
"/event-create",
116+
expect.objectContaining({
117+
foo: "bar",
118+
nameSpace: "main",
119+
sitekey: "test-site-key",
120+
})
121+
);
122+
});
123+
});
124+
101125
describe("eventViewPage", () => {
102126
it("should render /event-view-page when event exists", async () => {
103127
const req = {

server/events/event.service.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ describe("EventsService (Unit)", () => {
5656
describe("create", () => {
5757
it("should create an event with generated hash and resolved topics", async () => {
5858
const mainTopic = { _id: "t1", name: "Climate", wikidataId: "Q1" };
59-
const filterTopic = { _id: "t2", name: "Science", wikidataId: "Q2" };
6059
const expectedHash = crypto
6160
.createHash("md5")
6261
.update(`${mockCreateEventDto.name}-${mockCreateEventDto.startDate}`)
6362
.digest("hex");
6463
const createdEvent = { _id: "e1", data_hash: expectedHash };
6564

66-
mockTopicService.findOrCreateTopic
67-
.mockResolvedValueOnce(mainTopic)
68-
.mockResolvedValueOnce(filterTopic);
65+
mockTopicService.findOrCreateTopic.mockResolvedValueOnce(mainTopic);
6966
mockEventModel.create.mockResolvedValue(createdEvent);
7067

7168
const result = await service.create(mockCreateEventDto as any);
7269

73-
expect(mockTopicService.findOrCreateTopic).toHaveBeenCalledTimes(2);
70+
expect(mockTopicService.findOrCreateTopic).toHaveBeenCalledTimes(1);
71+
expect(mockTopicService.findOrCreateTopic).toHaveBeenCalledWith({
72+
...mockCreateEventDto.mainTopic,
73+
name: mockCreateEventDto.mainTopic.label,
74+
});
7475
expect(mockEventModel.create).toHaveBeenCalledWith(
7576
expect.objectContaining({
7677
...mockCreateEventDto,
7778
data_hash: expectedHash,
78-
mainTopic,
79-
filterTopics: [filterTopic],
79+
mainTopic: mainTopic._id,
8080
})
8181
);
8282
expect(result).toEqual(createdEvent);

server/mocks/EventMock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export const mockCreateEventDto = {
2525
location: "NYC",
2626
startDate: new Date("2026-01-05T00:00:00.000Z"),
2727
endDate: new Date("2026-01-10T00:00:00.000Z"),
28-
mainTopic: { name: "Climate", wikidataId: "Q1" },
29-
filterTopics: [{ name: "Science", wikidataId: "Q2" }],
28+
mainTopic: { name: "Climate", label: "Climate", wikidataId: "Q1" },
3029
};
3130

3231
export const mockEventsService = {

server/tests/event.e2e.spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ describe("EventController (e2e)", () => {
3333
startDate: startDate.toISOString(),
3434
endDate: endDate.toISOString(),
3535
mainTopic: {
36+
label: mainTopicName,
3637
name: mainTopicName,
3738
wikidataId: "Q125928",
3839
},
39-
filterTopics: [
40-
{
41-
name: "Science",
42-
wikidataId: "Q336",
43-
},
44-
],
4540
});
4641

4742
beforeAll(async () => {
@@ -117,7 +112,6 @@ describe("EventController (e2e)", () => {
117112
expect(body).toHaveProperty("data_hash");
118113
expect(body.name).toEqual("Future Event Alpha");
119114
expect(body).toHaveProperty("mainTopic");
120-
expect(body).toHaveProperty("filterTopics");
121115
});
122116
});
123117

0 commit comments

Comments
 (0)