Skip to content

Commit

Permalink
Return the total count of all chains instead of the current page count (
Browse files Browse the repository at this point in the history
  • Loading branch information
PooyaRaki authored Dec 18, 2024
1 parent bd19957 commit 6a10de0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ describe('Chain schemas', () => {
expect(result.success).toBe(true);
});

it('should exclude invalid Chain items, adjusting the count accordingly', () => {
it('should exclude invalid Chain items', () => {
const chains = faker.helpers.multiple(() => chainBuilder().build(), {
count: { min: 1, max: 5 },
});
Expand All @@ -674,10 +674,6 @@ describe('Chain schemas', () => {
const result = ChainLenientPageSchema.safeParse(chainPage);

expect(result.success).toBe(true);
expect(result.success && result.data.results.length).toBe(
chains.length - 1,
);
expect(result.success && result.data.count).toBe(chains.length - 1);
});
});
});
3 changes: 1 addition & 2 deletions src/domain/entities/schemas/page.schema.factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('Page schema factory', () => {
},
);

it('should remove invalid items from results, reducing count accordingly', () => {
it('should remove invalid items from results', () => {
const results = faker.helpers.multiple(
() => ({ test: faker.lorem.word() }),
{ count: { min: 2, max: 5 } },
Expand All @@ -192,7 +192,6 @@ describe('Page schema factory', () => {

const result = Schema.safeParse(page);

expect(result.success && result.data.count).toBe(results.length - 1);
expect(result.success && result.data.results).toStrictEqual(
results.slice(1),
);
Expand Down
7 changes: 6 additions & 1 deletion src/domain/entities/schemas/page.schema.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ export function buildLenientPageSchema<T extends z.ZodTypeAny>(
return result.success ? [result.data] : [];
});

// Note: @TODO The `results` object includes a `count` property, which the client is not currently using.
// We validate the chains and subtract the invalid ones from the count.
// However, due to pagination, we can only validate the chains on the current page,
// meaning the count may still include invalid chains from subsequent pages.
// For now, it's acceptable to ignore these inaccuracies in the count.
// That said, we should address this issue in the future to ensure the count is fully accurate.
return {
...data,
count: results.length,
results,
};
});
Expand Down
2 changes: 0 additions & 2 deletions src/routes/chains/chains.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ describe('Chains Controller (Unit)', () => {
networkService.get.mockResolvedValueOnce({
data: rawify({
...chainsResponse,
// Ensure count does not include invalid chains
count: chainsResponse.results.length + invalidChains.length,
results: [...chainsResponse.results, ...invalidChains],
}),
status: 200,
Expand Down

0 comments on commit 6a10de0

Please sign in to comment.