Skip to content

Commit

Permalink
make sure unit tests are working
Browse files Browse the repository at this point in the history
  • Loading branch information
thatkookooguy committed Oct 31, 2024
1 parent 858f5f9 commit 2bb2028
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"files.autoSave": "off",
"files.associations": {
"*.json": "json"
},
Expand Down Expand Up @@ -187,5 +188,7 @@
"**/*.rb",
"**/*.go"
],
"angular.enable-strict-mode-prompt": false
"angular.enable-strict-mode-prompt": false,
"jest.jestCommandLine": "pnpm run test",
"jest.rootPath": "server/"
}
24 changes: 23 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
"typescript": "^5.6.2"
},
"jest": {
"setupFiles": [
"<rootDir>/setup-globals.ts"
],
"moduleFileExtensions": [
"js",
"json",
Expand All @@ -134,6 +137,25 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^@kb-auth$": "<rootDir>/auth/index",
"^@kb-config$": "<rootDir>/config/index",
"^@kb-decorators$": "<rootDir>/decorators/index",
"^@kb-filters$": "<rootDir>/filters/index",
"^@kb-guards$": "<rootDir>/guards/index",
"^@kb-interceptors$": "<rootDir>/interceptors/index",
"^@kb-middleware$": "<rootDir>/middleware/index",
"^@kb-models$": "<rootDir>/models/index",
"^@kb-organizations$": "<rootDir>/organizations/index",
"^@kb-pull-requests$": "<rootDir>/pull-requests/index",
"^@kb-repositories$": "<rootDir>/repositories/index",
"^@kb-session-user$": "<rootDir>/session-user/index",
"^@kb-shields$": "<rootDir>/shields/index",
"^@kb-users$": "<rootDir>/users/index",
"^@kb-webhooks$": "<rootDir>/webhooks/index",
"^@kb-systems$": "<rootDir>/systems/index",
"^@kb-tasks$": "<rootDir>/tasks/index"
}
}
}
11 changes: 11 additions & 0 deletions server/src/__snapshots__/app.controller.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AppController root should return "Hello World!" 1`] = `
ApiInfo {
"description": "test",
"license": "test",
"name": "test",
"repository": "test",
"version": "test",
}
`;
20 changes: 17 additions & 3 deletions server/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,36 @@ import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SmeeService } from '@kb-config';

jest.mock('fs-extra', () => ({
readJSON: jest.fn().mockResolvedValue({
name: 'test',
description: 'test',
version: 'test',
license: 'test',
repository: 'test',
})
}));

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

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

appController = app.get<AppController>(AppController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
it('should return "Hello World!"', async () => {
expect(appController.getApiDetails()).resolves.toMatchSnapshot();
});
});
});
20 changes: 20 additions & 0 deletions server/src/config/__mocks__/config.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AchievibitConfig } from "../achievibit.config";

export class ConfigServiceMock {
private _config: Partial<AchievibitConfig> = {};
appRoot = 'root/';

get config() {
return this._config || {};
}

set config(config: Partial<AchievibitConfig>) {
this._config = config;
}

clear() {
this._config = {};
}
}

export const configService = new ConfigServiceMock();
1 change: 1 addition & 0 deletions server/src/setup-globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jest.mock('./config/config.service');

0 comments on commit 2bb2028

Please sign in to comment.