mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: i18n types
This commit is contained in:
parent
f14f5a7422
commit
ef4f34fbab
@ -69,7 +69,7 @@ describe('LanguageController', () => {
|
|||||||
}).compile();
|
}).compile();
|
||||||
languageService = module.get<LanguageService>(LanguageService);
|
languageService = module.get<LanguageService>(LanguageService);
|
||||||
languageController = module.get<LanguageController>(LanguageController);
|
languageController = module.get<LanguageController>(LanguageController);
|
||||||
language = await languageService.findOne({ code: 'en' });
|
language = (await languageService.findOne({ code: 'en' })) as Language;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(jest.clearAllMocks);
|
afterEach(jest.clearAllMocks);
|
||||||
@ -92,7 +92,7 @@ describe('LanguageController', () => {
|
|||||||
|
|
||||||
expect(languageService.findOne).toHaveBeenCalledWith(language.id);
|
expect(languageService.findOne).toHaveBeenCalledWith(language.id);
|
||||||
expect(result).toEqualPayload(
|
expect(result).toEqualPayload(
|
||||||
languageFixtures.find(({ code }) => code === language.code),
|
languageFixtures.find(({ code }) => code === language.code) as Language,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -142,7 +142,9 @@ describe('LanguageController', () => {
|
|||||||
it('should mark a language as default', async () => {
|
it('should mark a language as default', async () => {
|
||||||
jest.spyOn(languageService, 'updateOne');
|
jest.spyOn(languageService, 'updateOne');
|
||||||
const translationUpdateDto = { isDefault: true };
|
const translationUpdateDto = { isDefault: true };
|
||||||
const frLang = await languageService.findOne({ code: 'fr' });
|
const frLang = (await languageService.findOne({
|
||||||
|
code: 'fr',
|
||||||
|
})) as Language;
|
||||||
const result = await languageController.updateOne(
|
const result = await languageController.updateOne(
|
||||||
frLang.id,
|
frLang.id,
|
||||||
translationUpdateDto,
|
translationUpdateDto,
|
||||||
@ -157,7 +159,9 @@ describe('LanguageController', () => {
|
|||||||
...translationUpdateDto,
|
...translationUpdateDto,
|
||||||
});
|
});
|
||||||
|
|
||||||
const enLang = await languageService.findOne({ code: 'en' });
|
const enLang = (await languageService.findOne({
|
||||||
|
code: 'en',
|
||||||
|
})) as Language;
|
||||||
expect(enLang.isDefault).toBe(false);
|
expect(enLang.isDefault).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -171,7 +175,9 @@ describe('LanguageController', () => {
|
|||||||
|
|
||||||
describe('deleteOne', () => {
|
describe('deleteOne', () => {
|
||||||
it('should throw when attempting to delete the default language', async () => {
|
it('should throw when attempting to delete the default language', async () => {
|
||||||
const defaultLang = await languageService.findOne({ isDefault: true });
|
const defaultLang = (await languageService.findOne({
|
||||||
|
isDefault: true,
|
||||||
|
})) as Language;
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
languageController.deleteOne(defaultLang.id),
|
languageController.deleteOne(defaultLang.id),
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
forwardRef,
|
forwardRef,
|
||||||
Global,
|
Global,
|
||||||
Inject,
|
Inject,
|
||||||
|
InternalServerErrorException,
|
||||||
Module,
|
Module,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { HttpAdapterHost } from '@nestjs/core';
|
import { HttpAdapterHost } from '@nestjs/core';
|
||||||
@ -54,6 +55,11 @@ export class I18nModule extends NativeI18nModule {
|
|||||||
|
|
||||||
static forRoot(options: I18nOptions): DynamicModule {
|
static forRoot(options: I18nOptions): DynamicModule {
|
||||||
const { imports, providers, controllers, exports } = super.forRoot(options);
|
const { imports, providers, controllers, exports } = super.forRoot(options);
|
||||||
|
if (!providers || !exports) {
|
||||||
|
throw new InternalServerErrorException(
|
||||||
|
'I18n: Unable to find providers and/or exports forRoot()',
|
||||||
|
);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
module: I18nModule,
|
module: I18nModule,
|
||||||
imports: (imports || []).concat([
|
imports: (imports || []).concat([
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
I18nService as NativeI18nService,
|
I18nService as NativeI18nService,
|
||||||
Path,
|
Path,
|
||||||
@ -34,6 +34,11 @@ export class I18nService<
|
|||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
let { lang } = options;
|
let { lang } = options;
|
||||||
|
|
||||||
|
if (!lang) {
|
||||||
|
throw new InternalServerErrorException('I18nService: lang is undefined');
|
||||||
|
}
|
||||||
|
|
||||||
lang = this.resolveLanguage(lang);
|
lang = this.resolveLanguage(lang);
|
||||||
|
|
||||||
// Translate block message, button text, ...
|
// Translate block message, button text, ...
|
||||||
|
|||||||
4
api/src/utils/test/fixtures/language.ts
vendored
4
api/src/utils/test/fixtures/language.ts
vendored
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
import { LanguageUpdateDto } from '@/i18n/dto/language.dto';
|
import { LanguageCreateDto } from '@/i18n/dto/language.dto';
|
||||||
import { LanguageModel } from '@/i18n/schemas/language.schema';
|
import { LanguageModel } from '@/i18n/schemas/language.schema';
|
||||||
|
|
||||||
export const languageFixtures: LanguageUpdateDto[] = [
|
export const languageFixtures: LanguageCreateDto[] = [
|
||||||
{
|
{
|
||||||
title: 'English',
|
title: 'English',
|
||||||
code: 'en',
|
code: 'en',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user