Skip to content

Commit

Permalink
test(zimic-test-client): verify search params restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-aquino committed Mar 11, 2024
1 parent e067cff commit 351d326
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ function declareDefaultClientTests(options: ClientTestDeclarationOptions) {

async function listUsers(filters: UserListSearchParams = {}) {
const searchParams = new HttpSearchParams(filters);
const request = new Request(`http://localhost:3000/users?${searchParams}`, { method: 'GET' });
const request = new Request(`http://localhost:3000/users?${searchParams.toString()}`, {
method: 'GET',
});
return fetch(request);
}

Expand Down Expand Up @@ -413,10 +415,15 @@ function declareDefaultClientTests(options: ClientTestDeclarationOptions) {
it('should list users filtered by name', async () => {
const user = users[0];

const listTracker = authInterceptor.get('/users').respond({
status: 200,
body: [user],
});
const listTracker = authInterceptor
.get('/users')
.with({
searchParams: { name: user.name },
})
.respond({
status: 200,
body: [user],
});

const response = await listUsers({ name: user.name });
expect(response.status).toBe(200);
Expand Down Expand Up @@ -454,10 +461,15 @@ function declareDefaultClientTests(options: ClientTestDeclarationOptions) {
return -user.email.localeCompare(otherUser.email);
});

const listTracker = authInterceptor.get('/users').respond({
status: 200,
body: orderedUsers,
});
const listTracker = authInterceptor
.get('/users')
.with({
searchParams: { orderBy: ['email.desc'] },
})
.respond({
status: 200,
body: orderedUsers,
});

const response = await listUsers({
orderBy: ['email.desc'],
Expand Down

0 comments on commit 351d326

Please sign in to comment.