UNPKG

@jeremyckahn/farmhand

Version:
102 lines (86 loc) 2.68 kB
import { ACHIEVEMENT_COMPLETED } from '../../templates.js' vitest.mock('../../data/achievements.js', () => { return { default: [ { id: 'test-achievement', name: 'Test Achievement', description: '', rewardDescription: '', condition: (state: farmhand.state & { conditionSatisfied?: boolean }) => !state.conditionSatisfied, reward: (state: farmhand.state & { conditionSatisfied?: boolean }) => ({ ...state, conditionSatisfied: true, }), }, ], } }) describe('updateAchievements', () => { let updateAchievements: any beforeAll(async () => { updateAchievements = (await vitest.importActual('./updateAchievements.js')) .updateAchievements }) describe('achievement was not previously met', () => { describe('condition is not met', () => { test('does not update state', () => { const inputState = { completedAchievements: {}, conditionSatisfied: true, todaysNotifications: [], } const state = updateAchievements(inputState) expect(state).toBe(inputState) }) }) describe('condition is met', () => { test('updates state', () => { const inputState = { completedAchievements: {}, conditionSatisfied: false, todaysNotifications: [], } const state = updateAchievements(inputState) expect(state).toMatchObject({ completedAchievements: { 'test-achievement': true }, conditionSatisfied: true, todaysNotifications: [ { message: ACHIEVEMENT_COMPLETED('', { name: 'Test Achievement', rewardDescription: '', }), severity: 'success', }, ], }) }) }) }) describe('achievement was previously met', () => { describe('condition is not met', () => { test('does not update state', () => { const inputState = { completedAchievements: { 'test-achievement': true }, conditionSatisfied: true, todaysNotifications: [], } const state = updateAchievements(inputState) expect(state).toBe(inputState) }) }) describe('condition is met', () => { test('does not update state', () => { const inputState = { completedAchievements: { 'test-achievement': true }, conditionSatisfied: false, todaysNotifications: [], } const state = updateAchievements(inputState) expect(state).toBe(inputState) }) }) }) })