test: add tests for BitbucketCloudClient

Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
This commit is contained in:
Benjamin Janssens
2024-06-07 13:44:37 +02:00
parent 0aaf020359
commit c9af3ea5e2
@@ -107,4 +107,59 @@ describe('BitbucketCloudClient', () => {
expect(results).toHaveLength(1);
expect(results[0].slug).toEqual('repo1');
});
it('listProjectsByWorkspace', async () => {
server.use(
rest.get(
'https://api.bitbucket.org/2.0/workspaces/ws/projects',
(_, res, ctx) => {
const response = {
values: [
{
type: 'repository',
slug: 'project1',
} as Models.Project,
],
};
return res(ctx.json(response));
},
),
);
const pagination = client.listProjectsByWorkspace('ws');
const results = [];
for await (const result of pagination.iterateResults()) {
results.push(result);
}
expect(results).toHaveLength(1);
expect(results[0].slug).toEqual('project1');
});
it('listWorkspaces', async () => {
server.use(
rest.get('https://api.bitbucket.org/2.0/workspaces', (_, res, ctx) => {
const response = {
values: [
{
type: 'workspace',
slug: 'workspace1',
} as Models.Workspace,
],
};
return res(ctx.json(response));
}),
);
const pagination = client.listWorkspaces();
const results = [];
for await (const result of pagination.iterateResults()) {
results.push(result);
}
expect(results).toHaveLength(1);
expect(results[0].slug).toEqual('workspace1');
});
});