<commit_before>/* eslint-disable promise/always-return */
import { map } from "lodash"
import gql from "lib/gql"

import { runAuthenticatedQuery } from "schema/v2/test/utils"

describe("Me type", () => {
  let context
  let saleArtworkRootLoader
  beforeEach(() => {
    saleArtworkRootLoader = jest.fn()
    saleArtworkRootLoader
      .mockReturnValueOnce(
        Promise.resolve({
          id: "foo",
          _id: 0,
          artwork: { title: "Andy Warhol Skull" },
          sale_id: "else-auction",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar",
          _id: 1,
          artwork: { title: "Andy Warhol Skull" },
          highest_bid: { id: "hb2" },
          sale_id: "bar-auction",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "baz",
          _id: 2,
          artwork: { title: "Andy Warhol Skull" },
          sale_id: "else-auction",
        })
      )

    const saleLoader = jest.fn()
    saleLoader
      .mockReturnValueOnce(
        Promise.resolve({
          id: "else-auction",
          auction_state: "open",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar-auction",
          auction_state: "closed",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "else-auction",
          auction_state: "open",
        })
      )

    context = {
      saleLoader,
      saleArtworkRootLoader,
      meBidderPositionsLoader: sinon.stub().returns(
        Promise.resolve([
          {
            id: 0,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 0,
            highest_bid: null,
          },
          {
            id: 1,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 0,
            highest_bid: { id: "hb1" },
          },
          {
            id: 2,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 1,
            highest_bid: { id: "hb2" },
          },
          {
            id: 3,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 0,
            highest_bid: { id: "hb13" },
          },
          {
            id: 4,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 2,
            highest_bid: { id: "hb4" },
          },
        ])
      ),
    }
  })

  it("returns all bidder positions", () => {
    const query = gql`
      {
        me {
          bidder_positions {
            id
          }
        }
      }
    `
    return runAuthenticatedQuery(query, context).then(data => {
      expect(map(data.me.bidder_positions, "id").join("")).toEqual("01234")
    })
  })

  it("can return only current bidder positions", () => {
    const query = gql`
      {
        me {
          bidder_positions(current: true) {
            id
          }
        }
      }
    `
    return runAuthenticatedQuery(query, context).then(data => {
      expect(map(data.me.bidder_positions, "id").join("")).toEqual("14")
    })
  })

  it("does not fail for bidder positions with unpublished artworks", () => {
    const query = gql`
      {
        me {
          bidder_positions(current: true) {
            id
          }
        }
      }
    `
    context.saleArtworkRootLoader = jest
      .fn()
      .mockReturnValueOnce(Promise.resolve(new Error("Forbidden")))
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar",
          _id: 1,
          artwork: { title: "<NAME>" },
          highest_bid: { id: "hb2" },
          sale_id: "bar-auction",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "baz",
          _id: 0,
          artwork: { title: "Andy Warhol Skull" },
          sale_id: "else-auction",
        })
      )

    return runAuthenticatedQuery(query, context).then(data => {
      expect(map(data.me.bidder_positions, "id").join("")).toEqual("1")
    })
  })

  it("bidder positions can return is_winning based on sale artwork", () => {
    const query = gql`
      {
        me {
          bidder_positions {
            id
            is_winning
          }
        }
      }
    `

    context.saleArtworkRootLoader = jest
      .fn()
      .mockReturnValueOnce(Promise.resolve({}))
      .mockReturnValueOnce(Promise.resolve({}))
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar",
          _id: 1,
          artwork: { title: "Andy Warhol Skull" },
          highest_bid: { id: "hb2" },
          sale_id: "bar-auction",
        })
      )
      .mockReturnValueOnce(Promise.resolve({}))
      .mockReturnValueOnce(Promise.resolve({}))

    return runAuthenticatedQuery(query, context).then(data => {
      expect(data.me.bidder_positions[2].is_winning).toEqual(true)
    })
  })
})<commit_msg>Fix v2 bidder positions test<commit_after>/* eslint-disable promise/always-return */
import { map } from "lodash"
import gql from "lib/gql"

import { runAuthenticatedQuery } from "schema/v2/test/utils"

describe("Me type", () => {
  let context
  let saleArtworkRootLoader
  beforeEach(() => {
    saleArtworkRootLoader = jest.fn()
    saleArtworkRootLoader
      .mockReturnValueOnce(
        Promise.resolve({
          id: "foo",
          _id: 0,
          artwork: { title: "Andy Warhol Skull" },
          sale_id: "else-auction",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar",
          _id: 1,
          artwork: { title: "Andy Warhol Skull" },
          highest_bid: { id: "hb2" },
          sale_id: "bar-auction",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "baz",
          _id: 2,
          artwork: { title: "<NAME>" },
          sale_id: "else-auction",
        })
      )

    const saleLoader = jest.fn()
    saleLoader
      .mockReturnValueOnce(
        Promise.resolve({
          id: "else-auction",
          auction_state: "open",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar-auction",
          auction_state: "closed",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "else-auction",
          auction_state: "open",
        })
      )

    context = {
      saleLoader,
      saleArtworkRootLoader,
      meBidderPositionsLoader: sinon.stub().returns(
        Promise.resolve([
          {
            id: 0,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 0,
            highest_bid: null,
          },
          {
            id: 1,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 0,
            highest_bid: { id: "hb1" },
          },
          {
            id: 2,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 1,
            highest_bid: { id: "hb2" },
          },
          {
            id: 3,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 0,
            highest_bid: { id: "hb13" },
          },
          {
            id: 4,
            max_bid_amount_cents: 1000000,
            sale_artwork_id: 2,
            highest_bid: { id: "hb4" },
          },
        ])
      ),
    }
  })

  it("returns all bidder positions", () => {
    const query = gql`
      {
        me {
          bidderPositions {
            internalID
          }
        }
      }
    `
    return runAuthenticatedQuery(query, context).then(data => {
      expect(map(data.me.bidderPositions, "internalID").join("")).toEqual(
        "01234"
      )
    })
  })

  it("can return only current bidder positions", () => {
    const query = gql`
      {
        me {
          bidderPositions(current: true) {
            internalID
          }
        }
      }
    `
    return runAuthenticatedQuery(query, context).then(data => {
      expect(map(data.me.bidderPositions, "internalID").join("")).toEqual("14")
    })
  })

  it("does not fail for bidder positions with unpublished artworks", () => {
    const query = gql`
      {
        me {
          bidderPositions(current: true) {
            internalID
          }
        }
      }
    `
    context.saleArtworkRootLoader = jest
      .fn()
      .mockReturnValueOnce(Promise.resolve(new Error("Forbidden")))
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar",
          _id: 1,
          artwork: { title: "Andy Warhol Skull" },
          highest_bid: { id: "hb2" },
          sale_id: "bar-auction",
        })
      )
      .mockReturnValueOnce(
        Promise.resolve({
          id: "baz",
          _id: 0,
          artwork: { title: "Andy Warhol Skull" },
          sale_id: "else-auction",
        })
      )

    return runAuthenticatedQuery(query, context).then(data => {
      expect(map(data.me.bidderPositions, "internalID").join("")).toEqual("1")
    })
  })

  it("bidder positions can return is_winning based on sale artwork", () => {
    const query = gql`
      {
        me {
          bidderPositions {
            id
            isWinning
          }
        }
      }
    `

    context.saleArtworkRootLoader = jest
      .fn()
      .mockReturnValueOnce(Promise.resolve({}))
      .mockReturnValueOnce(Promise.resolve({}))
      .mockReturnValueOnce(
        Promise.resolve({
          id: "bar",
          _id: 1,
          artwork: { title: "Andy Warhol Skull" },
          highest_bid: { id: "hb2" },
          sale_id: "bar-auction",
        })
      )
      .mockReturnValueOnce(Promise.resolve({}))
      .mockReturnValueOnce(Promise.resolve({}))

    return runAuthenticatedQuery(query, context).then(data => {
      expect(data.me.bidderPositions[2].isWinning).toEqual(true)
    })
  })
})
{'fraction_non_alphanumeric': 0.12745804591784207, 'fraction_numerical': 0.014310717594975805, 'mean_word_length': 1.5583355280484592, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5390445', 'n_tokens_mistral': 3143, 'n_tokens_neox': 2996, 'n_words': 541}