it("does not redirect if the auction is not live", async () => { const mockAuctionQueries = { sale: { id: "foo", is_auction: true, auction_state: "open", is_live_open: false, }, me: { bidders: [ { id: "me", qualified_for_bidding: false, sale: { id: "foo", }, }, ], }, } metaphysics.mockResolvedValue(mockAuctionQueries) await routes.redirectLive(req, res, next) expect(res.redirect).not.toBeCalled() expect(next).toBeCalled() })
it("renders the index with the correct variables", async () => { const mockAuctionQueries = { sale: { id: "foo", is_auction: true, auction_state: "open", is_live_open: true, }, me: { bidders: [ { id: "me", qualified_for_bidding: true, sale: { id: "foo", }, }, ], }, } metaphysics.mockResolvedValue(mockAuctionQueries) // FIXME: Need to write more robust output test await routes.index(req, res, next) expect(res.send).toBeCalledWith("<html />") })
it("redirects on confirm if the auction is live and bidder is qualified", async () => { const mockAuctionQueries = { sale: { id: "foo", is_auction: true, auction_state: "open", is_live_open: true, }, me: { bidders: [ { id: "me", qualified_for_bidding: true, sale: { id: "foo", }, }, ], }, } metaphysics.mockResolvedValue(mockAuctionQueries) await routes.redirectLive(req, res, next) expect(res.redirect).toBeCalledWith("undefined/foo/login") })
xit("works even with the Metaphysics module throwing an error", async () => { metaphysics .mockReturnValueOnce({ sale: { is_auction: true } }) .mockRejectedValue("oops!") // FIXME: Need to write more robust output test await routes.index(req, res, next) expect(res.send).toBeCalledWith("<html />") })