Skip to content

Commit

Permalink
refactor: simplify cellar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed May 20, 2024
1 parent 5e444bb commit 85aa293
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/services/cellar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export class CellarService {
/**
* @private
*/
_uuid

constructor(uuidFactory = uuid) {
this._uuid = uuidFactory
}
_uuid = uuid

getItemInstancesInCellar = memoize(
/**
Expand Down
16 changes: 7 additions & 9 deletions src/services/cellar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import { pumpkin } from '../data/crops'

import { getYeastRequiredForWine } from '../utils/getYeastRequiredForWine'

import { CellarService } from './cellar'
import { cellarService } from './cellar'

const mockUuid = 'abc123'

const mockUuidFactory = () => {
return mockUuid
}

// @ts-expect-error
const stubCellarService = new CellarService(mockUuidFactory)
beforeEach(() => {
// @ts-expect-error
jest.spyOn(cellarService, '_uuid').mockReturnValue(mockUuid)
})

describe('CellarService', () => {
describe('generateKeg', () => {
test('generates a fermented crop keg', () => {
const keg = stubCellarService.generateKeg(pumpkin)
const keg = cellarService.generateKeg(pumpkin)

expect(keg).toEqual({
daysUntilMature: pumpkin.daysToFerment,
Expand All @@ -27,7 +25,7 @@ describe('CellarService', () => {
})

test('generates a wine keg', () => {
const keg = stubCellarService.generateKeg(wineChardonnay)
const keg = cellarService.generateKeg(wineChardonnay)

expect(keg).toEqual({
daysUntilMature: getYeastRequiredForWine(wineChardonnay.variety),
Expand Down

0 comments on commit 85aa293

Please sign in to comment.