TGD-30: FeatureFlags
This commit is contained in:
parent
ced62ddfba
commit
dfd149103e
8 changed files with 46 additions and 7 deletions
|
|
@ -20,6 +20,8 @@ import {ConfigModule} from "@nestjs/config";
|
||||||
import {MessagingModule} from "./messaging/messaging.module";
|
import {MessagingModule} from "./messaging/messaging.module";
|
||||||
import * as process from "process";
|
import * as process from "process";
|
||||||
import {OpenaiModule} from "./openai/openai.module";
|
import {OpenaiModule} from "./openai/openai.module";
|
||||||
|
import { FeatureflagController } from './featureflag/featureflag.controller';
|
||||||
|
import { FeatureflagService } from './featureflag/featureflag.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
|
@ -41,8 +43,8 @@ import {OpenaiModule} from "./openai/openai.module";
|
||||||
GiftsModule,
|
GiftsModule,
|
||||||
OpenaiModule
|
OpenaiModule
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController, FeatureflagController],
|
||||||
providers: [AppService, SocketGateway, SchedulerService],
|
providers: [AppService, SocketGateway, SchedulerService, FeatureflagService],
|
||||||
exports: [AppService, SocketGateway],
|
exports: [AppService, SocketGateway],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|
|
||||||
3
src/mocks/config-service.mock.ts
Normal file
3
src/mocks/config-service.mock.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export const ConfigServiceMock = {
|
||||||
|
|
||||||
|
}
|
||||||
4
src/mocks/featureflag-service.mock.ts
Normal file
4
src/mocks/featureflag-service.mock.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
export const FeatureflagServiceMock = {
|
||||||
|
getFeatureFlag: jest.fn(),
|
||||||
|
setFeatureFlag: jest.fn(),
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
export const SharedServiceMock = {
|
export const SharedServiceMock = {
|
||||||
|
setConfig: jest.fn(),
|
||||||
|
getConfig: jest.fn(),
|
||||||
sendSocketNotificationToAllClients: jest.fn(),
|
sendSocketNotificationToAllClients: jest.fn(),
|
||||||
}
|
}
|
||||||
3
src/mocks/voice-service.mock.ts
Normal file
3
src/mocks/voice-service.mock.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export const VoiceServiceMock = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -32,7 +32,6 @@ export class SchedulerService {
|
||||||
const giftsLeft = await this.giftsService.getRemainingPrizeCount();
|
const giftsLeft = await this.giftsService.getRemainingPrizeCount();
|
||||||
if (giftsLeft === 0) {
|
if (giftsLeft === 0) {
|
||||||
const state = await this.stateService.setState('main', 'finish');
|
const state = await this.stateService.setState('main', 'finish');
|
||||||
console.log(this.state);
|
|
||||||
this.sharedService.sendSocketNotificationToAllClients(
|
this.sharedService.sendSocketNotificationToAllClients(
|
||||||
'state_changed',
|
'state_changed',
|
||||||
state,
|
state,
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,15 @@ export class SharedService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getConfig(key: string) {
|
async getConfig(key: string) {
|
||||||
return this.configModel
|
const res = await this.configModel
|
||||||
.findOne({
|
.findOne({
|
||||||
key,
|
key,
|
||||||
})
|
})
|
||||||
.exec();
|
.exec();
|
||||||
|
return {
|
||||||
|
key: res.key,
|
||||||
|
value: res.value,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async setConfig(key: string, value: string) {
|
async setConfig(key: string, value: string) {
|
||||||
|
|
@ -35,11 +39,17 @@ export class SharedService {
|
||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
await record.save();
|
await record.save();
|
||||||
return record;
|
return {
|
||||||
|
key: record.key,
|
||||||
|
value: record.value,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cfgItem.value = value;
|
cfgItem.value = value;
|
||||||
await cfgItem.save();
|
await cfgItem.save();
|
||||||
return cfgItem;
|
return {
|
||||||
|
key: cfgItem.key,
|
||||||
|
value: cfgItem.value,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendSocketNotificationToAllClients(event: string, payload?: any) {
|
sendSocketNotificationToAllClients(event: string, payload?: any) {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,31 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { VoiceController } from './voice.controller';
|
import { VoiceController } from './voice.controller';
|
||||||
|
import {VoiceService} from "./voice.service";
|
||||||
|
import {VoiceServiceMock} from "../mocks/voice-service.mock";
|
||||||
|
import {Config} from "../schemas/config.schema";
|
||||||
|
import {ConfigService} from "@nestjs/config";
|
||||||
|
import {ConfigServiceMock} from "../mocks/config-service.mock";
|
||||||
|
|
||||||
describe('VoiceController', () => {
|
describe('VoiceController', () => {
|
||||||
let controller: VoiceController;
|
let controller: VoiceController;
|
||||||
|
let voiceService: VoiceService;
|
||||||
|
let configService: ConfigService;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
jest.clearAllMocks();
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [VoiceController],
|
controllers: [
|
||||||
|
VoiceController,
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: VoiceService, useValue: VoiceServiceMock },
|
||||||
|
{ provide: ConfigService, useValue: ConfigServiceMock },
|
||||||
|
]
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
controller = module.get<VoiceController>(VoiceController);
|
controller = module.get<VoiceController>(VoiceController);
|
||||||
|
voiceService = module.get<VoiceService>(VoiceService);
|
||||||
|
configService = module.get<ConfigService>(ConfigService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue