refactor: simplify unit conversion tests by importing utility functions directly
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import { RecipesService } from './recipes.service';
|
||||
import { normalizeUnit, convertUnit } from '../common/utils/units';
|
||||
|
||||
// Vi instansierar utan Prisma eftersom vi bara testar privata hjälpmetoder
|
||||
const service = new (RecipesService as any)(null);
|
||||
const convert = (q: number, from: string, to: string) =>
|
||||
(service as any).convertUnit(q, from, to, 'testprodukt');
|
||||
const normalize = (u: string) => (service as any).normalizeUnit(u);
|
||||
const convert = (q: number, from: string, to: string) => convertUnit(q, from, to);
|
||||
const normalize = (u: string) => normalizeUnit(u);
|
||||
|
||||
describe('RecipesService.normalizeUnit', () => {
|
||||
describe('normalizeUnit', () => {
|
||||
it('normaliserar aliaser', () => {
|
||||
expect(normalize('tesked')).toBe('tsk');
|
||||
expect(normalize('matsked')).toBe('msk');
|
||||
@@ -26,7 +23,7 @@ describe('RecipesService.normalizeUnit', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('RecipesService.convertUnit', () => {
|
||||
describe('convertUnit', () => {
|
||||
describe('viktkonvertering', () => {
|
||||
it('konverterar g → kg', () => {
|
||||
expect(convert(500, 'g', 'kg')).toBeCloseTo(0.5);
|
||||
|
||||
Reference in New Issue
Block a user