import type { Match } from 'requests'

import { getMatchAccess, MatchAccess } from '..'

type Args = {
  access?: boolean,
  calc?: boolean,
  date?: string,
  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.CanBuyMatch)
})

it('equals to  redirect type', () => {
  const match = createMatch({
    access: true,
    calc: false,
    date: '2020-01-01 00:00:00',
    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,
    date: '2020-01-01 00:00:00',
    live: true,
    sub: true,
  })

  expect(getMatchAccess(match)).toBe(MatchAccess.ViewMatchPopup)

  match = createMatch({
    access: true,
    calc: true,
    date: '2022-01-01 00:00:00',
    has_video: true,
    live: false,
    sub: true,
  })

  expect(getMatchAccess(match)).toBe(MatchAccess.RedirectToProfile)

  match = createMatch({
    access: true,
    calc: true,
    date: '2040-01-01 00:00:00',
    has_video: false,
    live: true,
    storage: true,
    sub: true,
  })

  expect(getMatchAccess(match)).toBe(MatchAccess.ViewMatchPopup)
})
