<commit_before>/* eslint-disable promise/always-return */
import moment from "moment"
import gql from "lib/gql"
import { runQuery } from "test/utils"
import trackedEntityLoaderFactory from "lib/loaders/loaders_with_authentication/tracked_entity"

describe("Show type", () => {
  let showData = null
  let rootValue = null
  let galaxyData = null

  beforeEach(() => {
    showData = {
      id: "new-museum-1-2015-triennial-surround-audience",
      _id: "abcdefg123456",
      start_at: "2015-02-25T12:00:00+00:00",
      end_at: "2015-05-24T12:00:00+00:00",
      press_release: "**foo** *bar*",
      displayable: true,
      partner: {
        id: "new-museum",
      },
      display_on_partner_profile: true,
      eligible_artworks_count: 8,
      is_reference: true,
      name: " Whitespace Abounds ",
      artists: [
        {
          id: "henry-moore",
          name: "<NAME>",
        },
        {
          id: "pierre-bonnard",
          name: "<NAME>",
        },
        {
          id: "pablo-picasso",
          name: "<NAME>",
        },
      ],
    }

    galaxyData = {
      id: "1",
      name: "Galaxy Partner",
      _links: "blah",
    }

    rootValue = {
      showLoader: sinon.stub().returns(Promise.resolve(showData)),
      showsWithHeadersLoader: sinon.stub().returns(
        Promise.resolve({
          body: [showData],
          headers: {
            "x-total-count": 1,
          },
        })
      ),
      galaxyGalleriesLoader: sinon.stub().returns(Promise.resolve(galaxyData)),
      partnerShowLoader: sinon.stub().returns(Promise.resolve(showData)),
    }
  })

  it("include true has_location flag for shows with location", async () => {
    showData.location = "test location"
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: true,
      },
    })
  })

  it("include true has_location flag for shows with fair_location", async () => {
    showData.fair = "test location"
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: true,
      },
    })
  })

  it("include true has_location flag for shows with partner_city", async () => {
    showData.partner_city = "test location"
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: true,
      },
    })
  })

  it("include false has_location flag for shows without any location", async () => {
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: false,
      },
    })
  })

  it("doesn't return a show that’s neither displayable nor a reference", async () => {
    showData.displayable = false
    showData.is_reference = false
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          name
        }
      }
    `
    try {
      await runQuery(query, rootValue)
      throw new Error("Did not expect query to not throw an error")
    } catch (error) {
      expect(error.message).toEqual("Show Not Found")
    }
  })

  it("returns a fair booth even with displayable set to true", async () => {
    showData.fair = {
      id: "the-art-show-2019",
      name: "The Art Show 2019",
    }

    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          name
          fair {
            id
            name
          }
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data.show.fair.id).toEqual("the-art-show-2019")
  })<commit_msg>Correct test logic<commit_after>/* eslint-disable promise/always-return */
import moment from "moment"
import gql from "lib/gql"
import { runQuery } from "test/utils"
import trackedEntityLoaderFactory from "lib/loaders/loaders_with_authentication/tracked_entity"

describe("Show type", () => {
  let showData = null
  let rootValue = null
  let galaxyData = null

  beforeEach(() => {
    showData = {
      id: "new-museum-1-2015-triennial-surround-audience",
      _id: "abcdefg123456",
      start_at: "2015-02-25T12:00:00+00:00",
      end_at: "2015-05-24T12:00:00+00:00",
      press_release: "**foo** *bar*",
      displayable: true,
      partner: {
        id: "new-museum",
      },
      display_on_partner_profile: true,
      eligible_artworks_count: 8,
      is_reference: true,
      name: " Whitespace Abounds ",
      artists: [
        {
          id: "henry-moore",
          name: "<NAME>",
        },
        {
          id: "pierre-bonnard",
          name: "<NAME>",
        },
        {
          id: "pablo-picasso",
          name: "<NAME>",
        },
      ],
    }

    galaxyData = {
      id: "1",
      name: "Galaxy Partner",
      _links: "blah",
    }

    rootValue = {
      showLoader: sinon.stub().returns(Promise.resolve(showData)),
      showsWithHeadersLoader: sinon.stub().returns(
        Promise.resolve({
          body: [showData],
          headers: {
            "x-total-count": 1,
          },
        })
      ),
      galaxyGalleriesLoader: sinon.stub().returns(Promise.resolve(galaxyData)),
      partnerShowLoader: sinon.stub().returns(Promise.resolve(showData)),
    }
  })

  it("include true has_location flag for shows with location", async () => {
    showData.location = "test location"
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: true,
      },
    })
  })

  it("include true has_location flag for shows with fair_location", async () => {
    showData.fair = "test location"
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: true,
      },
    })
  })

  it("include true has_location flag for shows with partner_city", async () => {
    showData.partner_city = "test location"
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: true,
      },
    })
  })

  it("include false has_location flag for shows without any location", async () => {
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          has_location
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data).toEqual({
      show: {
        has_location: false,
      },
    })
  })

  it("doesn't return a show that’s neither displayable nor a reference", async () => {
    showData.displayable = false
    showData.is_reference = false
    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          name
        }
      }
    `
    try {
      await runQuery(query, rootValue)
      throw new Error("Did not expect query to not throw an error")
    } catch (error) {
      expect(error.message).toEqual("Show Not Found")
    }
  })

  it("returns a fair booth even with displayable set to false", async () => {
    showData.fair = {
      id: "the-art-show-2019",
      name: "The Art Show 2019",
    }
    showData.displayable = false

    const query = gql`
      {
        show(id: "new-museum-1-2015-triennial-surround-audience") {
          name
          fair {
            id
            name
          }
        }
      }
    `
    const data = await runQuery(query, rootValue)
    expect(data.show.fair.id).toEqual("the-art-show-2019")
  })
{'fraction_non_alphanumeric': 0.13112033195020747, 'fraction_numerical': 0.021813870776526377, 'mean_word_length': 2.0053437833986463, 'pattern_counts': {'":': 2, '<': 9, '<?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': '6794941', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2703, 'n_words': 552}