{"size": 1655, "ext": "js", "max_stars_repo_path": "src/server/scripts/deck.test.js", "max_stars_repo_name": "danbuckland/honest-poker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/server/scripts/deck.test.js", "max_issues_repo_name": "danbuckland/honest-poker", "max_issues_repo_issues_event_min_datetime": "2021-02-05T14:20:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-26T15:19:30.000Z", "max_forks_repo_path": "src/server/scripts/deck.test.js", "max_forks_repo_name": "danbuckland/multiplayer-poker", "max_forks_repo_forks_event_min_datetime": "2021-02-26T13:20:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-26T13:20:55.000Z"}
{"max_stars_count": null, "max_issues_count": 10, "max_forks_count": 1, "avg_line_length": 27.5833333333, "max_line_length": 92, "alphanum_fraction": 0.6048338369}
import Deck from './deck'
import Card from './card'

describe('Deck constructor', () => {
  test('should return a Deck containing 52 cards', () => {
    const deck = new Deck()
    expect(deck.cards.length).toBe(52)
  })

  test('should return a deck where each card is unique', () => {
    const deck = new Deck()
    const allCardsUnique = (cards) => {
      let cardCodes = {}
      for (const card of cards) {
        if (cardCodes[card.code] === 1) {
          return false
        } else {
          cardCodes[card.code] = 1
        }
      }
      return true
    }
    expect(allCardsUnique(deck.cards)).toBe(true)
  })

  test('should consider Ace to have the highest value', () => {
    const deck = new Deck()
    let drawnCard = deck.draw()
    while (drawnCard.name !== 'Ace') {
      drawnCard = deck.draw()
    }
    expect(drawnCard.value).toBe(14)
  })
})

describe('Draw card function', () => {
  test('should return a single Card object when draw is called without an argument', () => {
    const deck = new Deck()
    const drawnCard = deck.draw()
    expect(drawnCard).toBeInstanceOf(Card)
  })

  test('should return an array containing 5 cards when 5 are requested', () => {
    const deck = new Deck()
    const drawnCards = deck.draw(5)
    expect(drawnCards.length).toBe(5)
    drawnCards.forEach((card) => {
      expect(card).toBeInstanceOf(Card)
    })
    expect(deck.cards.length).toBe(47)
  })

  test('should not be able to draw more than 52 cards from the deck', () => {
    const deck = new Deck()
    const drawnCards = deck.draw(53)
    expect(drawnCards.length).toBe(52)
    expect(deck.cards.length).toBe(0)
  })
})
