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
46 changes: 46 additions & 0 deletions apps/triggers/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Config } from 'jest';

const config: Config = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': [
'ts-jest',
{
tsconfig: {
module: 'commonjs',
esModuleInterop: true,
allowSyntheticDefaultImports: true,
},
},
],
},
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
collectCoverageFrom: [
'**/*.(t|j)s',
'!**/*.spec.ts',
'!**/node_modules/**',
'!**/dist/**',
],
transformIgnorePatterns: [
'node_modules/(?!(.*/)?(msgpackr|msgpackr-extract|bull|uuid)(/|$))',
],
moduleNameMapper: {
'^src/(.*)$': '<rootDir>/src/$1',
'^@/(.*)$': '<rootDir>/src/$1',
'^@lib/database$': '<rootDir>/../../packages/database/dist/index.js',
'^@lib/database/(.*)$': '<rootDir>/../../packages/database/dist/$1',
'^@lib/core$': '<rootDir>/../../packages/core/dist/index.js',
'^@lib/core/(.*)$': '<rootDir>/../../packages/core/dist/$1',
'^@lib/dhm-adapter$': '<rootDir>/../../packages/dhm-adapter/dist/index.js',
'^@lib/dhm-adapter/(.*)$': '<rootDir>/../../packages/dhm-adapter/dist/$1',
'^@lib/glofas-adapter$':
'<rootDir>/../../packages/glofas-adapter/dist/index.js',
'^@lib/glofas-adapter/(.*)$':
'<rootDir>/../../packages/glofas-adapter/dist/$1',
},
};

export default config;
42 changes: 42 additions & 0 deletions apps/triggers/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ReadableStream } from 'stream/web';
import { Blob } from 'buffer';
import { MessageChannel } from 'worker_threads';

if (typeof globalThis.ReadableStream === 'undefined') {
globalThis.ReadableStream = ReadableStream as any;
}

if (typeof globalThis.Blob === 'undefined') {
globalThis.Blob = Blob as any;
}

if (typeof globalThis.File === 'undefined') {
globalThis.File = class File extends Blob {
name: string;
lastModified: number;

constructor(
chunks: any[],
name: string,
options?: { lastModified?: number; type?: string },
) {
super(chunks, options);
this.name = name;
this.lastModified = options?.lastModified ?? Date.now();
}
} as any;
}

if (typeof globalThis.MessagePort === 'undefined') {
const { port1 } = new MessageChannel();
globalThis.MessagePort = port1.constructor as any;
}

if (typeof globalThis.DOMException === 'undefined') {
globalThis.DOMException = class DOMException extends Error {
constructor(message?: string, name?: string) {
super(message);
this.name = name || 'DOMException';
}
} as any;
}
20 changes: 0 additions & 20 deletions apps/triggers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,5 @@
"ts-jest": "^29.2.5",
"tsconfig-paths": "^4.2.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
},
"packageManager": "pnpm@8.14.1"
}
13 changes: 12 additions & 1 deletion apps/triggers/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SettingsService } from '@lib/core';
import { AppController } from './app.controller';
import { AppService } from './app.service';

describe('AppController', () => {
let appController: AppController;

const mockSettingsService = {
getPublic: jest.fn(),
};

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
providers: [
AppService,
{
provide: SettingsService,
useValue: mockSettingsService,
},
],
}).compile();

appController = app.get<AppController>(AppController);
Expand Down
8 changes: 6 additions & 2 deletions apps/triggers/src/phases/phases.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ jest.mock('cheerio', () => ({
import { Test, TestingModule } from '@nestjs/testing';
import { ClientProxy, RpcException } from '@nestjs/microservices';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { PrismaService } from '@lib/database';
import {
PrismaService,
ActivityStatus,
DataSource,
Phases,
} from '@lib/database';
import type { Queue } from 'bull';
import { BadRequestException } from '@nestjs/common';
import { PhasesService } from './phases.service';
Expand All @@ -20,7 +25,6 @@ import {
GetPhaseByName,
ConfigureThresholdPhaseDto,
} from './dto';
import { ActivityStatus, DataSource, Phases } from '@prisma/client';
import { of } from 'rxjs';

describe('PhasesService', () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/triggers/src/processors/schedule.processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { Job } from 'bull';
import { ScheduleProcessor } from './schedule.processor';
import { DhmService } from '../sources-data/dhm.service';
import { GlofasService } from '../sources-data/glofas.service';
import { BQUEUE, JOBS } from '../constant';
import { DataSource } from '@prisma/client';
import { DataSource } from '@lib/database';
import { AddTriggerStatementDto } from '../sources-data/dto';

describe('ScheduleProcessor', () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/triggers/src/processors/trigger.processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import type { Job } from 'bull';
import { TriggerProcessor } from './trigger.processor';
import { PhasesService } from '../phases/phases.service';
import { BQUEUE, JOBS } from '../constant';
import { DataSource } from '@prisma/client';
import { DataSource } from '@lib/database';

describe('TriggerProcessor', () => {
let processor: TriggerProcessor;
Expand Down
2 changes: 1 addition & 1 deletion apps/triggers/src/sources-data/dto/get-source-data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { validate } from 'class-validator';
import { GetSouceDataDto, SourceDataType } from './get-source-data';
import { DataSource } from '@prisma/client';
import { DataSource } from '@lib/database';

describe('GetSouceDataDto', () => {
it('should be defined', () => {
Expand Down
1 change: 1 addition & 0 deletions apps/triggers/src/sources-data/glofas.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SourcesDataService } from './sources-data.service';
import { of } from 'rxjs';

jest.mock('@lib/database', () => ({
...jest.requireActual('@lib/database'),
SettingsService: {
get: jest.fn().mockImplementation((key) => {
if (key === 'DATASOURCE.GLOFAS') {
Expand Down
11 changes: 9 additions & 2 deletions apps/triggers/src/stats/stat.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PrismaService } from '@lib/database';
import { ConfigModule } from '@nestjs/config';
import { PrismaModule, PrismaService } from '@lib/database';
import { ActivityService } from 'src/activity/activity.service';
import { StatsModule } from './stat.module';
import { StatsService } from './stat.service';
Expand All @@ -20,7 +21,13 @@ describe('StatsModule', () => {

beforeEach(async () => {
module = await Test.createTestingModule({
imports: [StatsModule],
imports: [
ConfigModule.forRoot({ isGlobal: true }),
PrismaModule.forRootWithConfig({
isGlobal: true,
}),
StatsModule,
],
})
.overrideProvider(PrismaService)
.useValue(mockPrismaService)
Expand Down
16 changes: 14 additions & 2 deletions apps/triggers/src/trigger-history/trigger-history.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ import { Test, TestingModule } from '@nestjs/testing';
import { TriggerHistoryModule } from './trigger-history.module';
import { TriggerHistoryController } from './trigger-history.controller';
import { TriggerHistoryService } from './trigger-history.service';
import { PrismaService } from '@lib/database';
import { PrismaModule, PrismaService } from '@lib/database';
import { ConfigModule } from '@nestjs/config';

describe('TriggerHistoryModule', () => {
let triggerHistoryModule: TriggerHistoryModule;

beforeEach(async () => {
triggerHistoryModule = new TriggerHistoryModule();
triggerHistoryModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
PrismaModule.forRootWithConfig({
isGlobal: true,
}),
TriggerHistoryModule,
],
})
.overrideProvider(PrismaService)
.useValue({})
.compile();
});

it('should be defined', () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/triggers/src/trigger/trigger.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { CreateTriggerDto, GetTriggersDto, UpdateTriggerDto } from './dto';
import { EventEmitter2 } from '@nestjs/event-emitter';

// Mock the paginator function
jest.mock('@rumsan/prisma', () => ({
...jest.requireActual('@rumsan/prisma'),
jest.mock('@lib/database', () => ({
...jest.requireActual('@lib/database'),
paginator: () => jest.fn(),
}));

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"dev": "turbo run dev",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"test": "turbo run test",
"test:watch": "turbo run test:watch",
"check-types": "turbo run check-types",
"clean": "find . -name 'node_modules' -type d -prune -exec rm -rf '{}' + && find . -name 'dist' -exec rm -rf '{}' + && find . -name '.turbo' -exec rm -rf '{}' + && find . -name '.log' -exec rm -rf '{}' +"
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
},
"db:format": {
"cache": false
},
"test": {},
"test:watch": {
"cache": false,
"persistent": true
}
}
}