diff --git a/package.json b/package.json index 2192ed2..7b22295 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hyperplay/quests-ui", - "version": "0.1.7", + "version": "0.1.8", "description": "", "main": "index.js", "scripts": { diff --git a/src/helpers/getPlaystreakQuestStatus.test.ts b/src/helpers/getPlaystreakQuestStatus.test.ts index 5415012..1ee74a4 100644 --- a/src/helpers/getPlaystreakQuestStatus.test.ts +++ b/src/helpers/getPlaystreakQuestStatus.test.ts @@ -115,6 +115,64 @@ describe('get playstreak quest status test', () => { } expect(getPlaystreakQuestStatus(quest, playstreak)).toEqual('ACTIVE') }) + + test('Quest status is undefined for COMPLETED status quest with min playstreak not met', () => { + const quest: Quest = { + id: 0, + project_id: '0123', + name: 'a quest', + type: 'PLAYSTREAK', + status: 'COMPLETED', + description: 'description', + deposit_contracts: [], + quest_external_game: null, + num_of_times_repeatable: 1, + eligibility: { + steam_games: [], + play_streak: { + required_playstreak_in_days: 10, + minimum_session_time_in_seconds: 100 + } + } + } + const playstreak: UserPlayStreak = { + current_playstreak_in_days: 1, + completed_counter: 0, + accumulated_playtime_today_in_seconds: 100, + last_play_session_completed_datetime: '0' + } + expect(getPlaystreakQuestStatus(quest, playstreak)).toEqual(undefined) + }) + + test('Quest status is READY_FOR_CLAIM for COMPLETED status quest with min playstreak met', () => { + const quest: Quest = { + id: 0, + project_id: '0123', + name: 'a quest', + type: 'PLAYSTREAK', + status: 'COMPLETED', + description: 'description', + deposit_contracts: [], + quest_external_game: null, + num_of_times_repeatable: 1, + eligibility: { + steam_games: [], + play_streak: { + required_playstreak_in_days: 10, + minimum_session_time_in_seconds: 100 + } + } + } + const playstreak: UserPlayStreak = { + current_playstreak_in_days: 10, + completed_counter: 0, + accumulated_playtime_today_in_seconds: 100, + last_play_session_completed_datetime: '0' + } + expect(getPlaystreakQuestStatus(quest, playstreak)).toEqual( + 'READY_FOR_CLAIM' + ) + }) }) export {} diff --git a/src/helpers/getPlaystreakQuestStatus.ts b/src/helpers/getPlaystreakQuestStatus.ts index fabe64d..3e246b5 100644 --- a/src/helpers/getPlaystreakQuestStatus.ts +++ b/src/helpers/getPlaystreakQuestStatus.ts @@ -4,7 +4,7 @@ import { Quest, UserPlayStreak } from '@hyperplay/utils' export function getPlaystreakQuestStatus( quest: Quest, questPlayStreak: UserPlayStreak -): QuestLogInfo['state'] { +): QuestLogInfo['state'] | undefined { const completedCounter = questPlayStreak.completed_counter const numTimesCompleteable = quest.num_of_times_repeatable @@ -23,6 +23,8 @@ export function getPlaystreakQuestStatus( (gameIsInfinitelyCompleteable || gameHasMoreFiniteCompletionsPossible) ) { return 'READY_FOR_CLAIM' + } else if (quest.status === 'COMPLETED') { + return undefined } else if (gameIsInfinitelyCompleteable) { return 'ACTIVE' } else if (!gameHasMoreFiniteCompletionsPossible) {