-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(products): find merchants, minor event fixes (#567)
- Loading branch information
Showing
17 changed files
with
351 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { MerchantsResponseResolvers } from "./../../types.generated.js"; | ||
export const MerchantsResponse: MerchantsResponseResolvers = { | ||
/* Implement MerchantsResponse resolver logic here */ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { QueryResolvers } from "./../../../types.generated.js"; | ||
export const merchants: NonNullable<QueryResolvers["merchants"]> = async ( | ||
_parent, | ||
_arg, | ||
ctx, | ||
) => { | ||
const findManyMerchantsResult = await ctx.products.merchants.findMany(ctx); | ||
if (!findManyMerchantsResult.ok) { | ||
throw findManyMerchantsResult.error; | ||
} | ||
return findManyMerchantsResult.data; | ||
}; |
69 changes: 69 additions & 0 deletions
69
src/graphql/products/resolvers/Query/merchants.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { UnauthorizedError, errorCodes } from "~/domain/errors.js"; | ||
import { createMockApolloServer } from "~/graphql/test-clients/mock-apollo-server.js"; | ||
import { graphql } from "~/graphql/test-clients/unit/gql.js"; | ||
import { Result } from "~/lib/result.js"; | ||
|
||
describe("Product queries", () => { | ||
it("returns all merchants", async () => { | ||
const { client, productService } = createMockApolloServer(); | ||
|
||
productService.merchants.findMany.mockResolvedValue( | ||
Result.success({ | ||
merchants: [], | ||
total: 0, | ||
}), | ||
); | ||
|
||
const { data } = await client.query({ | ||
query: graphql(` | ||
query Merchants { | ||
merchants { | ||
merchants { | ||
id | ||
} | ||
total | ||
} | ||
} | ||
`), | ||
}); | ||
|
||
expect(data).toEqual({ | ||
merchants: { | ||
merchants: [], | ||
total: 0, | ||
}, | ||
}); | ||
}); | ||
|
||
it("throws if it encounters an error", async () => { | ||
const { client, productService } = createMockApolloServer(); | ||
|
||
productService.merchants.findMany.mockResolvedValue( | ||
Result.error(new UnauthorizedError("")), | ||
); | ||
|
||
const { errors } = await client.query({ | ||
query: graphql(` | ||
query Merchants { | ||
merchants { | ||
merchants { | ||
id | ||
} | ||
total | ||
} | ||
} | ||
`), | ||
}); | ||
|
||
expect(errors).toBeDefined(); | ||
expect(errors).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
extensions: expect.objectContaining({ | ||
code: errorCodes.ERR_UNAUTHORIZED, | ||
}), | ||
}), | ||
]), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.