Пример #1
0
    it("returns data from gravity", () => {
      const query = `
        {
          sale(id: "foo-foo") {
            sale_artworks_connection(first: 10) {
              pageInfo {
                hasNextPage
              }
              edges {
                node {
                  id
                }
              }
            }
          }
        }
      `
      sale.eligible_sale_artworks_count = 20
      const rootValue = {
        saleArtworksLoader: () => Promise.resolve(fill(Array(sale.eligible_sale_artworks_count), { id: "some-id" })),
      }

      return runAuthenticatedQuery(query, rootValue).then(data => {
        expect(data).toMatchSnapshot()
      })
    })
Пример #2
0
 it("returns increments from the minimum next bid cents if the user has no lot standings", async () => {
   const data = await runAuthenticatedQuery(query, rootValue)
   expect(data.sale_artwork.increments.slice(0, 5)).toEqual([
     {
       cents: 351000,
       display: "€3,510",
     },
     {
       cents: 355000,
       display: "€3,550",
     },
     {
       cents: 360000,
       display: "€3,600",
     },
     {
       cents: 365000,
       display: "€3,650",
     },
     {
       cents: 370000,
       display: "€3,700",
     },
   ])
 })
Пример #3
0
    it("returns artworks for a collection", () => {
      const artworksPath = resolve("test", "fixtures", "gravity", "artworks_array.json")
      const artworks = JSON.parse(readFileSync(artworksPath, "utf8"))
      gravity
        .withArgs("collection/saved-artwork/artworks", { size: 10, offset: 0, total_count: true, user_id: "user-42" })
        .returns(Promise.resolve({ body: artworks, headers: { "x-total-count": 10 } }))

      const query = `
        {
          collection(id: "saved-artwork") {
            artworks_connection(first:10) {
              edges {
                node {
                  id
                  title
                }
              }
            }
          }
        }
      `
      return runAuthenticatedQuery(query).then(data => {
        expect(data).toMatchSnapshot()
      })
    })
  it("creates a submission and returns its new data payload", () => {
    const mutation = gql`
      mutation {
        addAssetToConsignmentSubmission(
          input: { asset_type: "image", gemini_token: "12345", submission_id: "123", clientMutationId: "123" }
        ) {
          asset {
            submission_id
            gemini_token
          }
        }
      }
    `

    const rootValue = {
      assetCreateLoader: () =>
        Promise.resolve({
          id: "106",
          gemini_token: "12345",
          submission_id: "123",
        }),
    }

    expect.assertions(1)
    return runAuthenticatedQuery(mutation, rootValue).then(data => {
      expect(data).toMatchSnapshot()
    })
  })
  it("updates a submission and returns its new data payload", () => {
    const mutation = gql`
      mutation {
        updateConsignmentSubmission(
          input: { id: "108", artist_id: "andy-warhol", depth: "123", clientMutationId: "123123" }
        ) {
          clientMutationId
          consignment_submission {
            depth
          }
        }
      }
    `

    const rootValue = {
      submissionUpdateLoader: () =>
        Promise.resolve({
          id: "106",
          artist_id: "andy-warhol",
          authenticity_certificate: true,
          depth: "1000",
        }),
    }

    expect.assertions(1)
    return runAuthenticatedQuery(mutation, rootValue).then(data => {
      expect(data).toMatchSnapshot()
    })
  })
  it("creates a submission and returns its new data payload", () => {
    const mutation = gql`
      mutation {
        createGeminiEntryForAsset(
          input: {
            template_key: "convection-staging"
            source_key: "2OSuAo_FAxJGHgGy0H2f-g/Orta2 2.jpg"
            source_bucket: "artsy-media-uploads"
            metadata: { id: 144, _type: "Consignment" }
          }
        ) {
          asset {
            token
          }
        }
      }
    `

    const rootValue = {
      createNewGeminiEntryAssetLoader: () =>
        Promise.resolve({
          token: "zVHJce-Fey3OIsazH8WDTg",
          image_urls: {},
          clientMutationId: "1231",
        }),
    }

    expect.assertions(1)
    return runAuthenticatedQuery(mutation, rootValue).then(data => {
      expect(data).toMatchSnapshot()
    })
  })
    it("returns artworks grouped by artist", () => {
      const query = `
        {
          me {
            followsAndSaves {
              bundledArtworksByArtist(first: 10) {
                pageInfo {
                  hasNextPage
                }
                edges {
                  node {
                    summary
                    artists
                  }
                }
              }
            }
          }
        }
      `

      const artworkStub = { artist: { id: "percy-z", name: "Percy Z" } }

      const artwork1 = assign({}, artworkStub, { title: "Artwork1" })
      const artwork2 = assign({}, artworkStub, { title: "Artwork2" })

      const expectedConnectionData = {
        pageInfo: {
          hasNextPage: true,
        },
        edges: [
          {
            node: {
              summary: "2 Works Added",
              artists: "Percy Z",
            },
          },
        ],
      }

      const artworkResponse = {
        headers: { "x-total-count": 11 },
        body: [artwork1, artwork2],
      }

      return runAuthenticatedQuery(query, {
        followedArtistsArtworksLoader: () => Promise.resolve(artworkResponse),
      }).then(({ me: { followsAndSaves: { bundledArtworksByArtist } } }) => {
        expect(bundledArtworksByArtist).toEqual(expectedConnectionData)
      })
    })
Пример #8
0
  it("returns the correct state when you are outbid on a work", () => {
    gravity
      // LotStanding fetch
      .onCall(0)
      .returns(
        Promise.resolve([
          {
            sale_artwork: {
              id: "untitled",
              reserve_status: "reserve_not_met",
            },
            max_position: {
              id: 0,
              max_bid_amount_cents: 90000,
              sale_artwork_id: "untitled",
            },
            leading_position: {
              id: 0,
              max_bid_amount_cents: 90000,
              sale_artwork_id: "untitled",
            },
          },
        ])
      )

    const query = `
      {
        me {
          bidder_status(artwork_id: "untitled", sale_id: "active-auction") {
            is_highest_bidder
            most_recent_bid {
              id
            }
            active_bid {
              id
            }
          }
        }
      }
    `

    return runAuthenticatedQuery(query).then(({ me }) => {
      expect(me).toEqual({
        bidder_status: {
          is_highest_bidder: false,
          most_recent_bid: { id: "0" },
          active_bid: null,
        },
      })
    })
  })
Пример #9
0
 it("can return only current bidder positions", () => {
   const query = gql`
     {
       me {
         bidder_positions(current: true) {
           id
         }
       }
     }
   `
   return runAuthenticatedQuery(query).then(data => {
     expect(map(data.me.bidder_positions, "id").join("")).toEqual("14")
   })
 })
Пример #10
0
  it("returns the correct state when you are the top bid but reserve is not met", () => {
    const lotStanding = [
      {
        sale_artwork: {
          id: "untitled",
          reserve_status: "reserve_not_met",
        },
        max_position: {
          id: 0,
          max_bid_amount_cents: 90000,
          sale_artwork_id: "untitled",
        },
        leading_position: {
          id: 0,
          max_bid_amount_cents: 90000,
          sale_artwork_id: "untitled",
        },
      },
    ]

    const query = `
      {
        me {
          lot_standing(artwork_id: "untitled", sale_id: "active-auction") {
            is_highest_bidder
            is_leading_bidder
            most_recent_bid {
              id
            }
            active_bid {
              id
            }
          }
        }
      }
    `

    return runAuthenticatedQuery(query, {
      lotStandingLoader: () => Promise.resolve(lotStanding),
    }).then(({ me }) => {
      expect(me).toEqual({
        lot_standing: {
          is_highest_bidder: false,
          is_leading_bidder: true,
          most_recent_bid: { id: "0" },
          active_bid: null,
        },
      })
    })
  })
Пример #11
0
 it("returns all bidder positions", () => {
   const query = gql`
     {
       me {
         bidder_positions {
           id
         }
       }
     }
   `
   return runAuthenticatedQuery(query).then(data => {
     expect(map(data.me.bidder_positions, "id").join("")).toEqual("01234")
   })
 })
Пример #12
0
 it("bidder positions can return is_winning based on sale artwork", () => {
   const query = gql`
     {
       me {
         bidder_positions {
           id
           is_winning
         }
       }
     }
   `
   return runAuthenticatedQuery(query).then(data => {
     expect(data.me.bidder_positions[2].is_winning).toEqual(true)
   })
 })
Пример #13
0
 it("does not fail for bidder positions with unpublished artworks", () => {
   const query = gql`
     {
       me {
         bidder_positions(current: true) {
           id
         }
       }
     }
   `
   gravity.onCall(3).returns(Promise.reject(new Error("Forbidden")))
   return runAuthenticatedQuery(query).then(data => {
     expect(map(data.me.bidder_positions, "id").join("")).toEqual("1")
   })
 })
Пример #14
0
 it("generates a Global ID", () => {
   const query = `
     {
       me {
         __id
       }
     }
   `
   return runAuthenticatedQuery(query).then(data => {
     expect(data).toEqual({
       me: {
         __id: globalId,
       },
     })
   })
 })
Пример #15
0
    it("returns collection metadata", () => {
      gravity.withArgs("collection/saved-artwork", { user_id: "user-42" }).returns(Promise.resolve(gravityData))

      const query = `
        {
          collection(id: "saved-artwork") {
            name
            private
            default
          }
        }
      `
      return runAuthenticatedQuery(query).then(data => {
        expect(data).toMatchSnapshot()
      })
    })
Пример #16
0
  it("follows a gene", () => {
    const mutation = `
      mutation {
        followGene(input: { gene_id: "pop-art" }) {
          gene {
            id
            name
          }
        }
      }
    `

    const rootValue = {
      followGeneLoader: () =>
        Promise.resolve({
          gene: {
            family: {},
            id: "pop-art",
            name: "Pop Art",
            image_url: "",
            image_urls: {},
            display_name: null,
          },
        }),
      geneLoader: () =>
        Promise.resolve({
          family: {
            id: "styles-and-movements",
          },
          id: "pop-art",
          name: "Pop Art",
          browseable: true,
        }),
    }

    const expectedGeneData = {
      gene: {
        id: "pop-art",
        name: "Pop Art",
      },
    }

    expect.assertions(1)
    return runAuthenticatedQuery(mutation, rootValue).then(({ followGene }) => {
      expect(followGene).toEqual(expectedGeneData)
    })
  })
  it("creates a submission and returns its new data payload", () => {
    const mutation = `
      mutation {
        requestCredentialsForAssetUpload(
          input: { name: "convection-staging", acl: "private", clientMutationId: "1231" }
        ) {
          asset {
            signature
            credentials
            policy_encoded
          }
        }
      }
    `

    const rootValue = {
      createNewGeminiAssetLoader: () =>
        Promise.resolve({
          policy_encoded: "12345==",
          policy_document: {
            expiration: "2017-09-28T03:08:11.000Z",
            conditions: [
              {
                bucket: "artsy-data-uploads",
              },
              ["starts-with", "$key", "11RuACCaTK8ydW_DESA"],
              {
                acl: "private",
              },
              {
                success_action_status: "201",
              },
              ["content-length-range", 0, 104857600],
              ["starts-with", "$Content-Type", ""],
            ],
          },
          signature: "12345=",
          credentials: "AKIA123456789",
          clientMutationId: "1231",
        }),
    }

    expect.assertions(1)
    return runAuthenticatedQuery(mutation, rootValue).then(data => {
      expect(data).toMatchSnapshot()
    })
  })
Пример #18
0
  it("correctly determines if a lot is not part of a live and open auction", () => {
    const query = `
      {
        me {
          lot_standing(artwork_id: "untitled", sale_id: "active-auction") {
            sale {
              is_live_open
            }
          }
        }
      }
    `

    const lotStanding = [
      {
        bidder: {
          sale: {
            id: "a-live-auction",
          },
        },
        sale_artwork: {
          id: "untitled",
          reserve_status: "reserve_not_met",
        },
      },
    ]

    const notALiveOpenSale = {
      auction_state: "open",
      live_start_at: moment().add(2, "days"),
      currency: "$",
      is_auction: true,
    }

    return runAuthenticatedQuery(query, {
      lotStandingLoader: () => Promise.resolve(lotStanding),
      saleLoader: () => Promise.resolve(notALiveOpenSale),
    }).then(({ me }) => {
      expect(me).toEqual({
        lot_standing: {
          sale: { is_live_open: false },
        },
      })
    })
  })
Пример #19
0
 it("should pass the proper inline fragment AST", () => {
   const query = `
     {
       node(__id: "${globalId}") {
         ... on Me {
           id
         }
       }
     }
   `
   return runAuthenticatedQuery(query).then(data => {
     expect(data).toEqual({
       node: {
         id: "user-42",
       },
     })
   })
 })
    it("returns sanitized messages", () => {
      const query = `
        {
          me {
            suggested_artists(artist_id: "pablo-picasso") {
              id
              birthday
            }
          }
        }
      `

      return runAuthenticatedQuery(query, rootValue).then(
        ({ me: conversation }) => {
          expect(conversation).toMatchSnapshot()
        }
      )
    })
Пример #21
0
    it("returns the sales along with the registration status", () => {
      const query = `
        {
          me {
            sale_registrations {
              is_registered
              sale {
                name
              }
            }
          }
        }
      `

      gravity
        // Sale fetch
        .onCall(0)
        .returns(
          Promise.resolve([
            {
              name: "Foo Sale",
              currency: "$",
              is_auction: true,
            },
            {
              name: "Bar Sale",
              currency: "$",
              is_auction: true,
            },
          ])
        )
        // Registration fetches
        .onCall(1)
        .returns(Promise.resolve([]))
        .onCall(2)
        .returns(Promise.resolve([{ id: "bidder-id" }]))

      return runAuthenticatedQuery(query).then(({ me: { sale_registrations } }) => {
        expect(sale_registrations).toEqual([
          { is_registered: false, sale: { name: "Foo Sale" } },
          { is_registered: true, sale: { name: "Bar Sale" } },
        ])
      })
    })
  it("updates the user profile and returns its new data payload", () => {
    const mutation = gql`
      mutation {
        updateMyUserProfile(
          input: {
            collector_level: 1
            clientMutationId: "1232"
            phone: "1234890"
            location: { address: "123 my street" }
            price_range_min: -1
            price_range_max: 1000000000000
          }
        ) {
          user {
            name
            phone
            location {
              city
              address
            }
            price_range
          }
        }
      }
    `

    const rootValue = {
      updateMeLoader: () =>
        Promise.resolve({
          id: "106",
          name: "andy-warhol",
          phone: "1234890",
          location: {
            address: "123 my street",
          },
          price_range: "-1:1000000000000",
        }),
    }

    expect.assertions(1)
    return runAuthenticatedQuery(mutation, rootValue).then(data => {
      expect(data).toMatchSnapshot()
    })
  })
Пример #23
0
 it("returns a list of users matching array of ids", async () => {
   const usersLoader = (data) => {
     if (data.id) {
       return Promise.resolve(
         data.id.map(id => ({ id }))
       )
     }
     throw new Error("Unexpected invocation")
   }
   const query = gql`
     {
       users(ids: ["5a9075da8b3b817ede4f8767"]) {
         id
       }
     }
   `
   const { users } = await runAuthenticatedQuery(query, { usersLoader })
   expect(users[0].id).toEqual("5a9075da8b3b817ede4f8767")
 })
Пример #24
0
 it("resolves a node", () => {
   const query = `
     {
       node(__id: "${globalId}") {
         __typename
         ... on Me {
           id
         }
       }
     }
   `
   return runAuthenticatedQuery(query).then(data => {
     expect(data).toEqual({
       node: {
         __typename: "Me",
         id: "user-42",
       },
     })
   })
 })
Пример #25
0
 it("returns false if user is not found by email", async () => {
   const notFoundUser = { error: "User Not Found" }
   const error = new Error(notFoundUser)
   error.statusCode = 404
   const userByEmailLoader = data => {
     if (data) {
       return Promise.resolve(notFoundUser)
     }
     throw error
   }
   const query = gql`
     {
       user(email: "*****@*****.**") {
         userAlreadyExists
       }
     }
   `
   const { user } = await runAuthenticatedQuery(query, { userByEmailLoader })
   expect(user.userAlreadyExists).toEqual(false)
 })
Пример #26
0
    it("returns bidder ids for the requested sale", () => {
      const query = `
        {
          me {
            bidders(sale_id: "the-fun-sale") {
              id
            }
          }
        }
      `
      const response = () =>
        Promise.resolve([{ id: "Foo ID" }, { id: "Bar ID" }])
      const meBiddersLoader = jest.fn(response)

      return runAuthenticatedQuery(query, { meBiddersLoader }).then(
        ({ me: { bidders } }) => {
          expect(meBiddersLoader).toBeCalledWith({ sale_id: "the-fun-sale" })
          expect(bidders).toEqual([{ id: "Foo ID" }, { id: "Bar ID" }])
        }
      )
    })
Пример #27
0
    it("returns bidder ids that the user is registered in sales for", () => {
      const query = `
        {
          me {
            bidders {
              id
            }
          }
        }
      `

      const response = () =>
        Promise.resolve([{ id: "Foo ID" }, { id: "Bar ID" }])
      const meBiddersLoader = jest.fn(response)

      return runAuthenticatedQuery(query, { meBiddersLoader }).then(
        ({ me: { bidders } }) => {
          expect(bidders).toEqual([{ id: "Foo ID" }, { id: "Bar ID" }])
        }
      )
    })
Пример #28
0
  it("returns true if a user exist", async () => {
    const foundUser = {
      id: "123456",
      _id: "000012345",
      name: "foo bar",
    }
    const userByEmailLoader = data => {
      if (data) {
        return Promise.resolve(foundUser)
      }
      throw new Error("Unexpected invocation")
    }
    const query = gql`
      {
        user(email: "*****@*****.**") {
          userAlreadyExists
        }
      }
    `

    const { user } = await runAuthenticatedQuery(query, { userByEmailLoader })
    expect(user.userAlreadyExists).toEqual(true)
  })
Пример #29
0
  it("makes a call for popular artists to the auth'd popularArtistsLoader", () => {
    const query = gql`
      {
        popular_artists {
          artists {
            id
          }
        }
      }
    `

    const rootValue = {
      authenticatedPopularArtistsLoader: () =>
        Promise.resolve([
          { birthday: "1900", artworks_count: 100, id: "ortina" },
          { birthday: "1900", artworks_count: 100, id: "xtina" },
        ]),
    }

    expect.assertions(1)
    return runAuthenticatedQuery(query, rootValue).then(data => {
      expect(data).toMatchSnapshot()
    })
  })
  it("updates a submission and returns its new data payload", () => {
    const mutation = gql`
      mutation {
        createConsignmentSubmission(
          input: {
            artist_id: "andy-warhol"
            clientMutationId: "2"
            authenticity_certificate: true
            dimensions_metric: CM
          }
        ) {
          clientMutationId
          consignment_submission {
            artist_id
            authenticity_certificate
            id
            dimensions_metric
          }
        }
      }
    `
    const rootValue = {
      submissionCreateLoader: () =>
        Promise.resolve({
          id: "106",
          artist_id: "andy-warhol",
          authenticity_certificate: true,
          dimensions_metric: "cm",
        }),
    }

    expect.assertions(1)
    return runAuthenticatedQuery(mutation, rootValue).then(data => {
      expect(data).toMatchSnapshot()
    })
  })