/* eslint-disable promise/always-return */
import { runQuery } from "schema/v2/test/utils"

describe("Artist type", () => {
  const artist = {
    id: "percy-z",
    birthday: "2012",
  }

  const contemporaryArtistsResponse = {
    headers: { "x-total-count": 35 },
    body: [{ id: "contemporary-percy-z", birthday: "2012" }],
  }
  const mainArtistsResponse = {
    headers: { "x-total-count": 35 },
    body: [{ id: "percy-z", birthday: "2012" }],
  }
  const relatedContemporaryArtistsLoader = jest
    .fn()
    .mockReturnValue(Promise.resolve(contemporaryArtistsResponse))

  const relatedMainArtistsLoader = jest
    .fn()
    .mockReturnValue(Promise.resolve(mainArtistsResponse))

  const artistLoader = () => Promise.resolve(artist)
  const context = {
    relatedContemporaryArtistsLoader,
    relatedMainArtistsLoader,
    artistLoader,
    relatedGenesLoader: () => Promise.resolve([{ id: "catty-gene" }]),
  }

  it("returns contemporary artists", () => {
    const query = `
      {
        artist(id: "percy-z") {
          related {
            artists(kind: CONTEMPORARY, first: 10) {
              pageCursors {
                first {
                  page
                }
                around {
                  page
                }
                last {
                  page
                }
              }
              edges {
                node {
                  id
                }
              }
            }
          }
        }
      }
    `

    return runQuery(query, context).then(
      ({
        artist: {
          related: {
            artists: { pageCursors, edges },
          },
        },
      }) => {
        // Check expected page cursors exist in response.
        const { first, around, last } = pageCursors
        expect(first).toEqual(null)
        expect(last).toEqual(null)
        expect(around.length).toEqual(4)
        let index
        for (index = 0; index < 4; index++) {
          expect(around[index].page).toBe(index + 1)
        }
        // Check auction result included in edges.
        expect(edges[0].node.id).toEqual("contemporary-percy-z")
      }
    )
  })

  it("returns main related artists", () => {
    const query = `
      {
        artist(id: "percy-z") {
          related {
            artists(kind: MAIN, first: 10) {
              pageCursors {
                first {
                  page
                }
                around {
                  page
                }
                last {
                  page
                }
              }
              edges {
                node {
                  id
                }
              }
            }
          }
        }
      }
    `

    return runQuery(query, context).then(
      ({
        artist: {
          related: {
            artists: { pageCursors, edges },
          },
        },
      }) => {
        // Check expected page cursors exist in response.
        const { first, around, last } = pageCursors
        expect(first).toEqual(null)
        expect(last).toEqual(null)
        expect(around.length).toEqual(4)
        let index
        for (index = 0; index < 4; index++) {
          expect(around[index].page).toBe(index + 1)
        }
        // Check auction result included in edges.
        expect(edges[0].node.id).toEqual("percy-z")
      }
    )
  })

  it("returns related genes", () => {
    const query = `
      {
        artist(id: "percy-z") {
          related {
            genes(first: 10) {
              edges {
                node {
                  id
                }
              }
            }
          }
        }
      }
    `

    return runQuery(query, context).then(
      ({
        artist: {
          related: {
            genes: { edges },
          },
        },
      }) => {
        expect(edges[0].node.id).toEqual("catty-gene")
      }
    )
  })
})

@@ -1060,24 +1060,34 @@
      artists
+Connection
 (kind: CONTE
@@ -1100,32 +1100,32 @@
 Y, first: 10) %7B%0A
-
               pa
@@ -1402,34 +1402,36 @@
                 
-id
+slug
 %0A               
@@ -1601,32 +1601,42 @@
          artists
+Connection
 : %7B pageCursors,
@@ -2104,34 +2104,36 @@
 t(edges%5B0%5D.node.
-id
+slug
 ).toEqual(%22conte
@@ -2314,16 +2314,26 @@
  artists
+Connection
 (kind: M
@@ -2644,34 +2644,36 @@
                 
-id
+slug
 %0A               
@@ -2851,16 +2851,26 @@
  artists
+Connection
 : %7B page
@@ -3346,34 +3346,36 @@
 t(edges%5B0%5D.node.
-id
+slug
 ).toEqual(%22percy
@@ -3611,18 +3611,20 @@
         
-id
+slug
 %0A       
@@ -3888,18 +3888,20 @@
 0%5D.node.
-id
+slug
 ).toEqua

Fix v2 artist related test