Skip to content

Commit

Permalink
Merge pull request #725 from joshunrau/v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joshunrau authored Feb 28, 2024
2 parents 950a6e8 + f4ba448 commit 156b678
Show file tree
Hide file tree
Showing 30 changed files with 1,266 additions and 949 deletions.
8 changes: 4 additions & 4 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"dependencies": {
"@casl/ability": "^6.5.0",
"@casl/prisma": "^1.4.1",
"@douglasneuroinformatics/crypto": "latest",
"@douglasneuroinformatics/nestjs": "latest",
"@douglasneuroinformatics/stats": "latest",
"@douglasneuroinformatics/utils": "latest",
"@douglasneuroinformatics/crypto": "^0.0.7",
"@douglasneuroinformatics/nestjs": "^3.0.0",
"@douglasneuroinformatics/stats": "^2.1.1",
"@douglasneuroinformatics/utils": "^1.2.2",
"@faker-js/faker": "^8.3.1",
"@nestjs/axios": "^3.0.1",
"@nestjs/common": "^10.3.0",
Expand Down
10 changes: 2 additions & 8 deletions apps/api/src/auth/__tests__/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { Test } from '@nestjs/testing';
import { beforeEach, describe, expect, it } from 'vitest';

import { type MockedInstance, createMock } from '@/testing/testing.utils';

import { AuthController } from '../auth.controller';
import { AuthService } from '../auth.service';

Expand All @@ -15,12 +14,7 @@ describe('AuthController', () => {
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
controllers: [AuthController],
providers: [
{
provide: AuthService,
useValue: createMock(AuthService)
}
]
providers: [MockFactory.createForService(AuthService)]
}).compile();
authController = moduleRef.get(AuthController);
authService = moduleRef.get(AuthService);
Expand Down
22 changes: 5 additions & 17 deletions apps/api/src/auth/__tests__/auth.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ValidationPipe } from '@douglasneuroinformatics/nestjs/core';
import { CryptoService } from '@douglasneuroinformatics/nestjs/modules';
import { MockFactory } from '@douglasneuroinformatics/nestjs/testing';
import { HttpStatus } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { type NestExpressApplication } from '@nestjs/platform-express';
Expand All @@ -9,7 +10,6 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import { AbilityFactory } from '@/ability/ability.factory';
import { ConfigurationService } from '@/configuration/configuration.service';
import { createMock } from '@/testing/testing.utils';
import { UsersService } from '@/users/users.service';

import { AuthController } from '../auth.controller';
Expand All @@ -24,25 +24,13 @@ describe('/auth', () => {
controllers: [AuthController],
providers: [
AuthService,
{
provide: AbilityFactory,
useValue: createMock(AbilityFactory)
},
MockFactory.createForService(AbilityFactory),
MockFactory.createForService(CryptoService),
MockFactory.createForService(JwtService),
MockFactory.createForService(UsersService),
{
provide: ConfigurationService,
useValue: {}
},
{
provide: CryptoService,
useValue: createMock(CryptoService)
},
{
provide: JwtService,
useValue: createMock(JwtService)
},
{
provide: UsersService,
useValue: createMock(UsersService)
}
]
}).compile();
Expand Down
22 changes: 5 additions & 17 deletions apps/api/src/auth/__tests__/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CryptoService } from '@douglasneuroinformatics/nestjs/modules';
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { NotFoundException, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { Test } from '@nestjs/testing';
import { beforeEach, describe, expect, it } from 'vitest';

import { AbilityFactory } from '@/ability/ability.factory';
import { ConfigurationService } from '@/configuration/configuration.service';
import { type MockedInstance, createMock } from '@/testing/testing.utils';
import { UsersService } from '@/users/users.service';

import { AuthService } from '../auth.service';
Expand All @@ -21,27 +21,15 @@ describe('AuthService', () => {
const moduleRef = await Test.createTestingModule({
providers: [
AuthService,
{
provide: AbilityFactory,
useValue: createMock(AbilityFactory)
},
MockFactory.createForService(AbilityFactory),
MockFactory.createForService(CryptoService),
MockFactory.createForService(JwtService),
MockFactory.createForService(UsersService),
{
provide: ConfigurationService,
useValue: {
get: (propertyPath: string) => propertyPath
}
},
{
provide: CryptoService,
useValue: createMock(CryptoService)
},
{
provide: JwtService,
useValue: createMock(JwtService)
},
{
provide: UsersService,
useValue: createMock(UsersService)
}
]
}).compile();
Expand Down
10 changes: 2 additions & 8 deletions apps/api/src/groups/__tests__/groups.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { Test } from '@nestjs/testing';
import { beforeEach, describe, expect, it } from 'vitest';

import { type MockedInstance, createMock } from '@/testing/testing.utils';

import { GroupsController } from '../groups.controller';
import { GroupsService } from '../groups.service';

Expand All @@ -13,12 +12,7 @@ describe('GroupsController', () => {
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
controllers: [GroupsController],
providers: [
{
provide: GroupsService,
useValue: createMock(GroupsService)
}
]
providers: [MockFactory.createForService(GroupsService)]
}).compile();
groupsController = moduleRef.get(GroupsController);
groupsService = moduleRef.get(GroupsService);
Expand Down
5 changes: 2 additions & 3 deletions apps/api/src/groups/__tests__/groups.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ValidationPipe } from '@douglasneuroinformatics/nestjs/core';
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { HttpStatus } from '@nestjs/common';
import { type NestExpressApplication } from '@nestjs/platform-express';
import { Test } from '@nestjs/testing';
Expand All @@ -8,8 +9,6 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';

import type { Model } from '@/prisma/prisma.types';
import { getModelToken } from '@/prisma/prisma.utils';
import { type MockedInstance } from '@/testing/testing.utils';
import { createMockModelProvider } from '@/testing/testing.utils';

import { GroupsController } from '../groups.controller';
import { GroupsService } from '../groups.service';
Expand All @@ -23,7 +22,7 @@ describe('/groups', () => {
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
controllers: [GroupsController],
providers: [GroupsService, createMockModelProvider('Group')]
providers: [GroupsService, MockFactory.createForModelToken(getModelToken('Group'))]
}).compile();

app = moduleRef.createNestApplication({
Expand Down
5 changes: 2 additions & 3 deletions apps/api/src/groups/__tests__/groups.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { ConflictException, NotFoundException } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { beforeEach, describe, expect, it } from 'vitest';

import type { Model } from '@/prisma/prisma.types';
import { getModelToken } from '@/prisma/prisma.utils';
import { type MockedInstance } from '@/testing/testing.utils';
import { createMockModelProvider } from '@/testing/testing.utils';

import { GroupsService } from '../groups.service';

Expand All @@ -15,7 +14,7 @@ describe('GroupsService', () => {

beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
providers: [GroupsService, createMockModelProvider('Group')]
providers: [GroupsService, MockFactory.createForModelToken(getModelToken('Group'))]
}).compile();
groupModel = moduleRef.get(getModelToken('Group'));
groupsService = moduleRef.get(GroupsService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { Test } from '@nestjs/testing';
import { beforeEach, describe, expect, it } from 'vitest';

import { type MockedInstance, createMock } from '@/testing/testing.utils';

import { InstrumentsController } from '../instruments.controller';
import { InstrumentsService } from '../instruments.service';

Expand All @@ -13,12 +12,7 @@ describe('InstrumentsController', () => {
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
controllers: [InstrumentsController],
providers: [
{
provide: InstrumentsService,
useValue: createMock(InstrumentsService)
}
]
providers: [MockFactory.createForService(InstrumentsService)]
}).compile();
instrumentsController = moduleRef.get(InstrumentsController);
instrumentsService = moduleRef.get(InstrumentsService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import { Test } from '@nestjs/testing';
// miniMentalStateExamination,
// montrealCognitiveAssessment
// } from '@open-data-capture/instrument-library';
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { ObjectId } from 'mongodb';
import request from 'supertest';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import { ConfigurationService } from '@/configuration/configuration.service';
import type { Model } from '@/prisma/prisma.types';
import { getModelToken } from '@/prisma/prisma.utils';
import { type MockedInstance, createMock } from '@/testing/testing.utils';
import { createMockModelProvider } from '@/testing/testing.utils';

import { InstrumentsController } from '../instruments.controller';
import { InstrumentsService } from '../instruments.service';
Expand All @@ -33,11 +32,8 @@ describe('/instruments', () => {
controllers: [InstrumentsController],
providers: [
InstrumentsService,
createMockModelProvider('Instrument'),
{
provide: ConfigurationService,
useValue: createMock(ConfigurationService)
}
MockFactory.createForModelToken(getModelToken('Instrument')),
MockFactory.createForService(ConfigurationService)
]
}).compile();

Expand Down
10 changes: 3 additions & 7 deletions apps/api/src/instruments/__tests__/instruments.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { Test } from '@nestjs/testing';
import { beforeEach, describe, expect, it } from 'vitest';

import { ConfigurationService } from '@/configuration/configuration.service';
import type { Model } from '@/prisma/prisma.types';
import { getModelToken } from '@/prisma/prisma.utils';
import { type MockedInstance, createMock } from '@/testing/testing.utils';
import { createMockModelProvider } from '@/testing/testing.utils';

import { InstrumentsService } from '../instruments.service';

Expand All @@ -17,11 +16,8 @@ describe('InstrumentsService', () => {
const moduleRef = await Test.createTestingModule({
providers: [
InstrumentsService,
createMockModelProvider('Instrument'),
{
provide: ConfigurationService,
useValue: createMock(ConfigurationService)
}
MockFactory.createForModelToken(getModelToken('Instrument')),
MockFactory.createForService(ConfigurationService)
]
}).compile();
instrumentsService = moduleRef.get(InstrumentsService);
Expand Down
10 changes: 8 additions & 2 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ async function bootstrap() {

const configurationService = app.get(ConfigurationService);
const logLevels: LogLevel[] = ['error', 'fatal', 'log', 'warn'];
configurationService.get('DEBUG') && logLevels.push('debug');
configurationService.get('VERBOSE') && logLevels.push('verbose');
if (configurationService.get('DEBUG')) {
console.log("Enabled 'debug' logs");
logLevels.push('debug');
}
if (configurationService.get('VERBOSE')) {
console.log("Enabled 'verbose' logs");
logLevels.push('verbose');
}
app.useLogger(logLevels);

app.enableCors();
Expand Down
10 changes: 3 additions & 7 deletions apps/api/src/subjects/__tests__/subjects.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ValidationPipe } from '@douglasneuroinformatics/nestjs/core';
import { CryptoService } from '@douglasneuroinformatics/nestjs/modules';
import { MockFactory, type MockedInstance } from '@douglasneuroinformatics/nestjs/testing';
import { HttpStatus } from '@nestjs/common';
import { type NestExpressApplication } from '@nestjs/platform-express';
import { Test } from '@nestjs/testing';
Expand All @@ -9,8 +10,6 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';

import type { Model } from '@/prisma/prisma.types';
import { getModelToken } from '@/prisma/prisma.utils';
import { type MockedInstance, createMock } from '@/testing/testing.utils';
import { createMockModelProvider } from '@/testing/testing.utils';

import { SubjectsController } from '../subjects.controller';
import { SubjectsService } from '../subjects.service';
Expand All @@ -26,11 +25,8 @@ describe('/subjects', () => {
controllers: [SubjectsController],
providers: [
SubjectsService,
{
provide: CryptoService,
useValue: createMock(CryptoService)
},
createMockModelProvider('Subject')
MockFactory.createForModelToken(getModelToken('Subject')),
MockFactory.createForService(CryptoService)
]
}).compile();

Expand Down
Loading

0 comments on commit 156b678

Please sign in to comment.