Skip to content

Commit

Permalink
feat(bulk-import): adding unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
its-mitesh-kumar committed Jan 8, 2025
1 parent d21cfb2 commit de3defc
Showing 1 changed file with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,121 @@ describe('bulkimports.ts unit tests', () => {
}
expect(resp.responseBody).toEqual(expectedResponse);

// Unit test for sort if empty string is provided sorting should be based on name in asc order
resp = await findAllImports(
{
logger,
config,
githubApiService: mockGithubApiService,
catalogHttpClient: mockCatalogHttpClient,
},
{
apiVersion,
},
{
pageNumber: 1,
pageSize: 6,
sortColumn: '',
sortOrder: '',
},
);
const sortedNames =
apiVersion === 'v2'
? resp?.responseBody?.imports?.map(
(importObj: { repository: { name: any } }) =>
importObj.repository.name,
)
: resp?.responseBody?.map(
(importObj: { repository: { name: any } }) =>
importObj.repository.name,
);
let expectedSortedArray = [
'my-repo-11',
'my-repo-123',
'my-repo-21',
'my-repo-22',
'my-repo-31',
'my-repo-32',
];
expect(sortedNames).toEqual(expectedSortedArray);

// sorting based on organization in asc order
resp = await findAllImports(
{
logger,
config,
githubApiService: mockGithubApiService,
catalogHttpClient: mockCatalogHttpClient,
},
{
apiVersion,
},
{
pageNumber: 1,
pageSize: 6,
sortColumn: 'repository.organization',
sortOrder: 'asc',
},
);

let sortedOrganization =
apiVersion === 'v2'
? resp?.responseBody?.imports?.map(
(importObj: { repository: { organization: any } }) =>
importObj.repository.organization,
)
: resp?.responseBody?.map(
(importObj: { repository: { organization: any } }) =>
importObj.repository.organization,
);
expectedSortedArray = [
'my-org-1',
'my-org-2',
'my-org-2',
'my-org-3',
'my-org-3',
'my-user',
];
expect(sortedOrganization).toEqual(expectedSortedArray);
// sorting based on organization in desc order
resp = await findAllImports(
{
logger,
config,
githubApiService: mockGithubApiService,
catalogHttpClient: mockCatalogHttpClient,
},
{
apiVersion,
},
{
pageNumber: 1,
pageSize: 6,
sortColumn: 'repository.organization',
sortOrder: 'desc',
},
);

sortedOrganization =
apiVersion === 'v2'
? resp?.responseBody?.imports?.map(
(importObj: { repository: { organization: any } }) =>
importObj.repository.organization,
)
: resp?.responseBody?.map(
(importObj: { repository: { organization: any } }) =>
importObj.repository.organization,
);
expectedSortedArray = [
'my-user',
'my-org-3',
'my-org-3',
'my-org-2',
'my-org-2',
'my-org-1',
];
expect(sortedOrganization).toEqual(expectedSortedArray);

// No data for this page
resp = await findAllImports(
{
Expand Down

0 comments on commit de3defc

Please sign in to comment.