Skip to content

Commit

Permalink
test: added and updated existing test for testpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
sundarlogan committed May 8, 2024
1 parent 0e3651a commit 4332813
Showing 1 changed file with 67 additions and 5 deletions.
72 changes: 67 additions & 5 deletions test/testCasePoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ const azureConfig: IAzureConfig = {
runName: 'sample',
}

const azureConfigWithConfigName: IAzureConfig = {
pat: 'v3e3pg4njfmzzcuoxwb4vja3trwbyafim4x4oww7sbcfbopfb3bq',
organizationUrl: 'https://dev.azure.com/organization',
projectId: '3cf7dbc9-cb1e-4240-93f2-9a5960ab3945',
planId: 12,
suiteId: 14,
runName: 'sample',
configurationName: 'stage',
}

describe('Validate http call to retrieve the testCase in the test Run', () => {
it('Should resolve an empty the promise if a valid AzureDevOps Axios client is passed', async () => {
const mockClient = {
Expand All @@ -35,22 +45,22 @@ describe('Validate http call to retrieve the testCase in the test Run', () => {
})
}
const result = getPoints(mockClient as unknown as AxiosInstance, azureConfig)
//await expect(result).resolves.toEqual([])
await expect(result).resolves.toEqual([])
})

it('Should return ids if data are wellformed from AzureDevOps API', async () => {
it('Should return all ids if data are wellformed with one default configuration from AzureDevOps API', async () => {
const mockClient = {
get: jest.fn(() => {
return new Promise((resolve, reject) => {
resolve({
data: {
value: [{
pointAssignments: [{ id: 1 }, { id: 2 }],
pointAssignments: [{ id: 1 , configurationName:'default' }],
configuration: {},
id: 1,
},
{
pointAssignments: [{ id: 3 }, { id: 4 }],
pointAssignments: [{ id: 3, configurationName:'default' }],
configuration: {},
id: 2,
}]
Expand All @@ -61,7 +71,59 @@ describe('Validate http call to retrieve the testCase in the test Run', () => {
})
}
const result = getPoints(mockClient as unknown as AxiosInstance, azureConfig)
//await expect(result).resolves.toEqual([1, 3])
await expect(result).resolves.toEqual([1, 3])
})

it('Should return matching ids of configurationName for wellformed data with multiple configurations from AzureDevOps API', async () => {
const mockClient = {
get: jest.fn(() => {
return new Promise((resolve, reject) => {
resolve({
data: {
value: [{
pointAssignments: [{ id: 1, configurationName: 'dev' }, { id: 2, configurationName: 'stage' }],
configuration: {},
id: 1,
},
{
pointAssignments: [{ id: 3, configurationName: 'dev' }, { id: 4, configurationName: 'stage' }],
configuration: {},
id: 2,
}]
},
headers:{}
})
})
})
}
const result = getPoints(mockClient as unknown as AxiosInstance, azureConfigWithConfigName)
await expect(result).resolves.toEqual([2, 4])
})

it('Should return empty if data are wellformed without no matching configuration from AzureDevOps API', async () => {
const mockClient = {
get: jest.fn(() => {
return new Promise((resolve, reject) => {
resolve({
data: {
value: [{
pointAssignments: [{ id: 1, configurationName: 'dev' }, { id: 2, configurationName: 'prod' }],
configuration: {},
id: 1,
},
{
pointAssignments: [{ id: 3, configurationName: 'dev' }, { id: 4, configurationName: 'prod' }],
configuration: {},
id: 2,
}]
},
headers:{}
})
})
})
}
const result = getPoints(mockClient as unknown as AxiosInstance, azureConfigWithConfigName)
await expect(result).resolves.toEqual([])
})

it('Should throw error an error if an empty AzureDevOps Axios client is passed', async () => {
Expand Down

0 comments on commit 4332813

Please sign in to comment.