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 * as process from "process";
|
||||
import {OpenaiModule} from "./openai/openai.module";
|
||||
import { FeatureflagController } from './featureflag/featureflag.controller';
|
||||
import { FeatureflagService } from './featureflag/featureflag.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -41,8 +43,8 @@ import {OpenaiModule} from "./openai/openai.module";
|
|||
GiftsModule,
|
||||
OpenaiModule
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, SocketGateway, SchedulerService],
|
||||
controllers: [AppController, FeatureflagController],
|
||||
providers: [AppService, SocketGateway, SchedulerService, FeatureflagService],
|
||||
exports: [AppService, SocketGateway],
|
||||
})
|
||||
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 = {
|
||||
setConfig: jest.fn(),
|
||||
getConfig: 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();
|
||||
if (giftsLeft === 0) {
|
||||
const state = await this.stateService.setState('main', 'finish');
|
||||
console.log(this.state);
|
||||
this.sharedService.sendSocketNotificationToAllClients(
|
||||
'state_changed',
|
||||
state,
|
||||
|
|
|
|||
|
|
@ -16,11 +16,15 @@ export class SharedService {
|
|||
}
|
||||
|
||||
async getConfig(key: string) {
|
||||
return this.configModel
|
||||
const res = await this.configModel
|
||||
.findOne({
|
||||
key,
|
||||
})
|
||||
.exec();
|
||||
return {
|
||||
key: res.key,
|
||||
value: res.value,
|
||||
}
|
||||
}
|
||||
|
||||
async setConfig(key: string, value: string) {
|
||||
|
|
@ -35,11 +39,17 @@ export class SharedService {
|
|||
value,
|
||||
});
|
||||
await record.save();
|
||||
return record;
|
||||
return {
|
||||
key: record.key,
|
||||
value: record.value,
|
||||
}
|
||||
}
|
||||
cfgItem.value = value;
|
||||
await cfgItem.save();
|
||||
return cfgItem;
|
||||
return {
|
||||
key: cfgItem.key,
|
||||
value: cfgItem.value,
|
||||
}
|
||||
}
|
||||
|
||||
sendSocketNotificationToAllClients(event: string, payload?: any) {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,31 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
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', () => {
|
||||
let controller: VoiceController;
|
||||
let voiceService: VoiceService;
|
||||
let configService: ConfigService;
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks();
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [VoiceController],
|
||||
controllers: [
|
||||
VoiceController,
|
||||
],
|
||||
providers: [
|
||||
{ provide: VoiceService, useValue: VoiceServiceMock },
|
||||
{ provide: ConfigService, useValue: ConfigServiceMock },
|
||||
]
|
||||
}).compile();
|
||||
|
||||
controller = module.get<VoiceController>(VoiceController);
|
||||
voiceService = module.get<VoiceService>(VoiceService);
|
||||
configService = module.get<ConfigService>(ConfigService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue