Skip to content

Commit

Permalink
Got tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpetro committed Feb 8, 2024
1 parent b3650e8 commit 377d464
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/irrigation-events/irrigation-events.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing'
import { IrrigationEventsController } from '@/irrigation-events/irrigation-events.controller'
import { MakerApiService } from './maker-api.service'
import { ViewmodelTransformService } from './viewmodel-transform.service'
import { IrrigationEventsService } from './irrigation-events.service'
import { ConfigModule } from '@nestjs/config'

describe('IrrigationEventsController', () => {
let controller: IrrigationEventsController

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot({ envFilePath: '.env.local' })],
controllers: [IrrigationEventsController],
providers: [IrrigationEventsService, MakerApiService, ViewmodelTransformService],
}).compile()

controller = module.get<IrrigationEventsController>(IrrigationEventsController)
Expand Down
2 changes: 2 additions & 0 deletions src/irrigation-events/irrigation-events.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Test, TestingModule } from '@nestjs/testing'
import { IrrigationEventsService } from '@/irrigation-events/irrigation-events.service'
import { ConfigModule } from '@nestjs/config'

describe('IrrigationEventsService', () => {
let service: IrrigationEventsService

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot({ envFilePath: '.env.local' })],
providers: [IrrigationEventsService],
}).compile()

Expand Down
13 changes: 10 additions & 3 deletions src/irrigation-events/irrigation-events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import * as queryBuilders from './queries'
@Injectable()
export class IrrigationEventsService {
private db: DocumentScope<IrrigationEventDocument>
private intervalTimeout: NodeJS.Timeout

public constructor(private configService: ConfigService<EnvironmentVariables, true>) {
public constructor(private configService: ConfigService<EnvironmentVariables, true>) {}

async onModuleInit() {
const nano = Nano({
url: this.configService.get<string>('COUCHDB_URL', { infer: true }),
requestDefaults: {
Expand All @@ -26,10 +29,14 @@ export class IrrigationEventsService {
this.configService.get<string>('DB_USERNAME', { infer: true }),
this.configService.get<string>('DB_PASSWORD', { infer: true })
)
nanoAuth()
await nanoAuth()

const authRefreshMinutes: number = this.configService.get<number>('DB_AUTH_REFRESH_MINUTES', { infer: true })
setInterval(nanoAuth, authRefreshMinutes * 60 * 1000)
this.intervalTimeout = setInterval(nanoAuth, authRefreshMinutes * 60 * 1000)
}

onModuleDestroy() {
clearInterval(this.intervalTimeout)
}

private async executeQuery(query: Nano.MangoQuery) {
Expand Down
20 changes: 20 additions & 0 deletions src/irrigation-events/maker-api.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing'
import { MakerApiService } from '@/irrigation-events/maker-api.service'
import { ConfigModule } from '@nestjs/config'

describe('MakerApiService', () => {
let service: MakerApiService

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot({ envFilePath: '.env.local' })],
providers: [MakerApiService],
}).compile()

service = module.get<MakerApiService>(MakerApiService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})
18 changes: 18 additions & 0 deletions src/irrigation-events/viewmodel-transform.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing'
import { ViewmodelTransformService } from '@/irrigation-events/viewmodel-transform.service'

describe('ViewmodelTransformService', () => {
let service: ViewmodelTransformService

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ViewmodelTransformService],
}).compile()

service = module.get<ViewmodelTransformService>(ViewmodelTransformService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})

0 comments on commit 377d464

Please sign in to comment.