Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Update getPlaystreakQuestStatus to hide if ineligible completed quest #40

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperplay/quests-ui",
"version": "0.1.7",
"version": "0.1.8",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
58 changes: 58 additions & 0 deletions src/helpers/getPlaystreakQuestStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 3 additions & 1 deletion src/helpers/getPlaystreakQuestStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,6 +23,8 @@ export function getPlaystreakQuestStatus(
(gameIsInfinitelyCompleteable || gameHasMoreFiniteCompletionsPossible)
) {
return 'READY_FOR_CLAIM'
} else if (quest.status === 'COMPLETED') {
return undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why undefined instead of addind another option to the type? I find a value like NOT_QUALIFIED better than the absence of value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want it to be confused with a QuestLogInfo['state'] value. undefined in this case means the quest shouldn't be shown to the user.

I do see where your coming from and would make the change if I weren't under a bit of a time crunch. This is a bit of a nitpick though

} else if (gameIsInfinitelyCompleteable) {
return 'ACTIVE'
} else if (!gameHasMoreFiniteCompletionsPossible) {
Expand Down
Loading