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
1 change: 1 addition & 0 deletions CONSUMER_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ submodule bump — each needs a matching change in the consuming app.
| `8ffe995` | `handle-email` webhook now guarded by `MailWebhookGuard` (checks `X-Webhook-Secret` header against `MAIL_WEBHOOK_SECRET`); Yemot gets a second, per-user-token-secured mount at `/yemot/handle-call/:secret` alongside the existing open one | Set `MAIL_WEBHOOK_SECRET` in `server/.env` and have n8n send that value as `X-Webhook-Secret` on its request to `handle-email` (no-op / stays open until this is set). No env var needed for Yemot — the per-user token is generated automatically and shown on the client's Tutorial page once `nra-client`'s matching change lands; users need to update their `ext.ini` to the new URL (old one keeps working during migration) | all 5 apps |
| `28a61f5` | `TestAppHelper` now wires `cookie-parser` itself; `utils/testing/e2e/test-utils.ts` adds `registerAndAuthenticate()` (register a test user + guarded Authentication-cookie extraction) and `asList()` (normalizes a CRUD list response that may be a plain array or `{ data: [...] }`) | Not required to keep working (purely additive), but each app's `server/test/*-crud.e2e-spec.ts` should swap its hand-rolled `Test.createTestingModule`/cookie-parser/cookie-regex/teardown boilerplate for `createTestApp()` + `registerAndAuthenticate()` + `asList()` to drop the duplication | react-admin-nestjs, event-management-nra, teacher-report-nra, student-report-nra, dnd-management-nra |
| `e876588` | Async job queue + scheduler (`JobsModule` in `BaseNraAppModule`, `Job`/`Schedule` entities) | Add `@nestjs/schedule` and `cron-parser` to `server/package.json`; add a migration creating the `jobs` and `schedules` tables; to actually process jobs on an instance, set `WORKER_ENABLED=true` (optionally `JOB_POLL_MS`, `JOB_WORKER_BATCH`) | all 5 apps, form-call |
| `e8c4d1b` | Removed unused v1 Yemot flow (`utils/yemot/yemot.module.ts`, `yemot.service.ts`, `chain.interface.ts`, `yemot.util.ts`, `yemot.exception.ts`; `yemot.interface.ts` now exports only `FormatString`). All apps already use v2 (`BaseYemotHandlerService`) | Confirm `server/src` imports none of the removed files (`grep -rn "utils/yemot/" server/src` — only `v2/`, `testing` and `FormatString` from `yemot.interface` may remain). Copy `.github/skills/yemot-integration/SKILL.md` from `multi-repo-codespace` so the skill points at v2 only | react-admin-nestjs |
98 changes: 0 additions & 98 deletions utils/yemot/__tests__/chain.interface.spec.ts

This file was deleted.

174 changes: 1 addition & 173 deletions utils/yemot/__tests__/yemot.interface.spec.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
import { DataSource, getRepository } from "typeorm";
import { FormatString, YEMOT_HANGUP_STEP, YemotProcessor, YemotRequest, YemotResponse } from "../yemot.interface";
import { YemotCall, YemotParams } from "@shared/entities/YemotCall.entity";
import { TextByUser } from "@shared/view-entities/TextByUser.entity";
import { User } from "@shared/entities/User.entity";
import util from "../yemot.util";

export class MockYemotRequest extends YemotRequest {
constructor(activeCall: any, dataSource: any) {
super(activeCall, dataSource);
}
getLessonFromLessonId(lessonId: number) {
return {} as any;
}
getKlassByKlassId(klassKey: number, klassId?: number) {
return {} as any;
}
getTeacherByPhone(phone: string) {
return {} as any;
}
getStudentsByKlassId(klassId: number) {
return [] as any;
}
saveReport(reportData: any, type: any) {
return {} as any;
}
async getExistingAttReports(klassId: string, lessonId: string, sheetName: string): Promise<any[]> {
return [];
}
async getExistingGradeReports(klassId: string, lessonId: string, sheetName: string): Promise<any[]> {
return [];
}
deleteExistingReports(existingReports: any[], type: any) {
return {} as any;
}
}
import { FormatString } from "../yemot.interface";

describe('FormatString', () => {
it('should replace placeholders with values', () => {
Expand All @@ -46,140 +11,3 @@ describe('FormatString', () => {
expect(result).toBe("Hello World!");
});
});

export const getMockDataSource = () => ({
getRepository: jest.fn().mockReturnValue({
findOne: jest.fn(),
findOneByOrFail: jest.fn(),
findOneBy: jest.fn(),
find: jest.fn(),
findBy: jest.fn(),
create: jest.fn(),
save: jest.fn(),
delete: jest.fn(),
})
} as unknown as DataSource);

class MockYemotProcessor extends YemotProcessor {
processCall(activeCall: YemotCall, body: YemotParams): Promise<YemotResponse> {
throw new Error("Method not implemented.");
}

getTextPublic(userId: number, textKey: string, ...args): Promise<string> {
return this.getText(userId, textKey, ...args);
}
}

describe('YemotProcessor', () => {
let dataSource: DataSource;
let yemotProcessor: MockYemotProcessor;

beforeEach(() => {
dataSource = getMockDataSource();
yemotProcessor = new MockYemotProcessor(dataSource);
});

it('should return formatted text for a given user and text key', async () => {
const userId = 1;
const textKey = "greeting";
const args = ["John"];
const textValue = "Hello {0}";

// Mock the database call
jest.spyOn(dataSource.getRepository(TextByUser), 'findOne').mockResolvedValue({ value: textValue } as TextByUser);

const result = await yemotProcessor.getTextPublic(userId, textKey, ...args);
expect(result).toBe("Hello John");
});

it('should handle cases where textKey does not exist', async () => {
const userId = 1;
const textKey = "nonexistent";

// Mock the database call
jest.spyOn(dataSource.getRepository(TextByUser), 'findOne').mockResolvedValue(null);

const result = await yemotProcessor.getTextPublic(userId, textKey);
expect(result).toBe(textKey);
});
});

describe('YemotRequest', () => {
let dataSource: DataSource;
let yemotRequest: YemotRequest;
let activeCall: YemotCall;

beforeEach(() => {
dataSource = getMockDataSource();
activeCall = new YemotCall();
activeCall.userId = 1;
yemotRequest = new MockYemotRequest(activeCall, dataSource);
});

it('should return the correct userId from the active call', () => {
const result = yemotRequest.getUserId();
expect(result).toBe(1);
});

it('should return user permissions for the given userId', async () => {
const user = { id: 1, permissions: ["READ", "WRITE"] };

// Mock the database call
jest.spyOn(yemotRequest, 'getUser').mockResolvedValue(user as User);

const result = await yemotRequest.getUserPermissions();
expect(result).toEqual(["READ", "WRITE"]);
});
});

describe('YemotResponse', () => {
let dataSource: DataSource;
let yemotResponse: YemotResponse;

beforeEach(() => {
dataSource = getMockDataSource();
yemotResponse = new YemotResponse(dataSource, 1);
});

it('should return the correct formatted text for a given text key', async () => {
const textKey = "greeting";
const args = ["John"];
const textValue = "Hello {0}";

// Mock the database call
jest.spyOn(dataSource.getRepository(TextByUser), 'findOne').mockResolvedValue({ value: textValue } as TextByUser);

const result = await yemotResponse.getText(textKey, ...args);
expect(result).toBe("Hello John");
});

it('should return the correct hangup step', () => {
const result = yemotResponse.hangup();
expect(result).toBe(YEMOT_HANGUP_STEP);
});

it('should clear all messages', () => {
yemotResponse.send("Test message");
yemotResponse.clear();
expect(yemotResponse.messages.length).toBe(0);
});

it('should correctly send a message with given parameters and options', () => {
yemotResponse.send("Test message", "param1", { option: "value" });
expect(yemotResponse.messages.length).toBe(1);
expect(yemotResponse.messages[0]).toEqual({ text: "Test message", param: "param1", options: { option: "value" } });
});

it('should correctly send a message with given parameters', async () => {
yemotResponse.send(yemotResponse.hangup());
expect(yemotResponse.messages.length).toBe(1);
const response = await yemotResponse.getResponse();
expect(response).toBe(util.send(util.hangup()));
});

it('should get the key for the text if not found', async () => {
jest.spyOn(dataSource.getRepository(TextByUser), 'findOne').mockResolvedValue(null);
const result = await yemotResponse.getText("test");
expect(result).toBe("test");
});
});
Loading