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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
run: npm run build

- name: Test
run: npm test
run: npm run test:cov
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@
"json",
"ts"
],
"rootDir": "test",
"rootDir": ".",
"roots": [
"<rootDir>/test",
"<rootDir>/src"
],
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.ts$": [
Expand All @@ -105,12 +109,20 @@
]
},
"collectCoverageFrom": [
"../src/**/*.{t,j}s"
"src/**/*.{t,j}s"
],
"coverageDirectory": "../coverage",
"coverageDirectory": "coverage",
"coverageThreshold": {
"global": {
"statements": 45,
"branches": 30,
"functions": 35,
"lines": 45
}
},
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/../src/$1"
"^src/(.*)$": "<rootDir>/src/$1"
}
},
"overrides": {
Expand Down
20 changes: 20 additions & 0 deletions src/modules/vendors/vendors.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConflictException, NotFoundException, ForbiddenException, UnauthorizedException, ExecutionContext } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { VendorsService } from './vendors.service';
import { VendorsController } from './vendors.controller';
import { SupabaseService } from '../../database/supabase.client';
import { VendorsRepository } from '../../database/repositories/vendors.repository';
import { VendorRegistryContractClient } from '../../stellar/contracts/clients/vendor-registry.client';
import { VendorType, VendorStatus } from './dto/vendor.dto';
import { AdminGuard } from '../../common/guards/admin.guard';
Expand All @@ -14,6 +16,8 @@ describe('VendorsModule', () => {
let mockSupabaseService: any;
let mockVendorRegistryClient: any;
let mockConfigService: any;
let mockVendorsRepository: any;
let mockCacheManager: any;
let adminGuard: AdminGuard;

const mockAdminWallet = 'GA3D5342W...ADMIN_WALLET_ADDRESS';
Expand Down Expand Up @@ -79,14 +83,30 @@ describe('VendorsModule', () => {
}),
};

// The methods under test read through supabaseService and the registry
// client; the repository and cache are wired only to satisfy DI.
mockVendorsRepository = {
findById: jest.fn(),
findAll: jest.fn(),
updateStatus: jest.fn(),
};

mockCacheManager = {
get: jest.fn(),
set: jest.fn(),
del: jest.fn(),
};

const module: TestingModule = await Test.createTestingModule({
controllers: [VendorsController],
providers: [
VendorsService,
AdminGuard,
{ provide: SupabaseService, useValue: mockSupabaseService },
{ provide: VendorsRepository, useValue: mockVendorsRepository },
{ provide: VendorRegistryContractClient, useValue: mockVendorRegistryClient },
{ provide: ConfigService, useValue: mockConfigService },
{ provide: CACHE_MANAGER, useValue: mockCacheManager },
],
}).compile();

Expand Down
Loading