fix(913): match card clickability fixes (#338)
* fix(913): match card clickability fixes * fix(913): review fixkeep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
35e82eff28
commit
c1570107be
@ -0,0 +1,70 @@ |
|||||||
|
import type { Match } from 'requests' |
||||||
|
|
||||||
|
import { getMatchAccess, MatchAccess } from '..' |
||||||
|
|
||||||
|
type Args = { |
||||||
|
access?: boolean, |
||||||
|
calc?: boolean, |
||||||
|
has_video?: boolean, |
||||||
|
live?: boolean, |
||||||
|
storage?: boolean, |
||||||
|
sub?: boolean, |
||||||
|
} |
||||||
|
|
||||||
|
const createMatch = (args: Args) => ({ |
||||||
|
...args, |
||||||
|
} as Match) |
||||||
|
|
||||||
|
it('equals to no country access type', () => { |
||||||
|
const match = createMatch({ |
||||||
|
access: false, |
||||||
|
sub: false, |
||||||
|
}) |
||||||
|
expect(getMatchAccess(match)).toBe(MatchAccess.NoCountryAccess) |
||||||
|
}) |
||||||
|
|
||||||
|
it('equals to redirect type', () => { |
||||||
|
const match = createMatch({ |
||||||
|
access: true, |
||||||
|
calc: false, |
||||||
|
has_video: true, |
||||||
|
sub: true, |
||||||
|
}) |
||||||
|
expect(getMatchAccess(match)).toBe(MatchAccess.RedirectToProfile) |
||||||
|
}) |
||||||
|
|
||||||
|
it('equals to can buy type', () => { |
||||||
|
const match = createMatch({ |
||||||
|
access: true, |
||||||
|
sub: false, |
||||||
|
}) |
||||||
|
expect(getMatchAccess(match)).toBe(MatchAccess.CanBuyMatch) |
||||||
|
}) |
||||||
|
|
||||||
|
it('equals to view match popup type', () => { |
||||||
|
let match = createMatch({ |
||||||
|
access: true, |
||||||
|
live: true, |
||||||
|
sub: true, |
||||||
|
}) |
||||||
|
expect(getMatchAccess(match)).toBe(MatchAccess.ViewMatchPopup) |
||||||
|
|
||||||
|
match = createMatch({ |
||||||
|
access: true, |
||||||
|
calc: true, |
||||||
|
has_video: true, |
||||||
|
live: false, |
||||||
|
sub: true, |
||||||
|
}) |
||||||
|
expect(getMatchAccess(match)).toBe(MatchAccess.ViewMatchPopup) |
||||||
|
|
||||||
|
match = createMatch({ |
||||||
|
access: true, |
||||||
|
calc: true, |
||||||
|
has_video: false, |
||||||
|
live: false, |
||||||
|
storage: true, |
||||||
|
sub: true, |
||||||
|
}) |
||||||
|
expect(getMatchAccess(match)).toBe(MatchAccess.ViewMatchPopup) |
||||||
|
}) |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
import type { Match } from 'requests' |
||||||
|
|
||||||
|
export enum MatchAccess { |
||||||
|
CanBuyMatch = 'CanBuyMatch', |
||||||
|
NoAccess = 'NoAccess', |
||||||
|
NoCountryAccess = 'NoCountryAccess', |
||||||
|
RedirectToProfile = 'RedirectToProfile', |
||||||
|
ViewMatchPopup = 'ViewMatchPopup', |
||||||
|
} |
||||||
|
|
||||||
|
export const getMatchAccess = ({ |
||||||
|
access, |
||||||
|
calc, |
||||||
|
has_video, |
||||||
|
live, |
||||||
|
storage, |
||||||
|
sub, |
||||||
|
}: Match) => { |
||||||
|
switch (true) { |
||||||
|
case !access: |
||||||
|
return MatchAccess.NoCountryAccess |
||||||
|
case !sub: |
||||||
|
return MatchAccess.CanBuyMatch |
||||||
|
case !calc && has_video: |
||||||
|
return MatchAccess.RedirectToProfile |
||||||
|
case live: |
||||||
|
case calc && (has_video || storage): |
||||||
|
return MatchAccess.ViewMatchPopup |
||||||
|
default: |
||||||
|
return MatchAccess.NoAccess |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue