-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-89645 || TestCaseId, attributes, description reporting (#19)
* add attributes method * add testCaseId method * add description method * update README.md * update description method * add unit tests * fix bindGlobalReportingApi * add task data
- Loading branch information
1 parent
45af22c
commit 9280c59
Showing
11 changed files
with
323 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ReportingApi } from '../reportingApi'; | ||
import * as vitest from 'vitest'; | ||
import { getTask } from './mocks/data'; | ||
import { RPTaskMeta } from '../models'; | ||
|
||
describe('test attributes reporting', () => { | ||
let task: vitest.Task; | ||
|
||
beforeEach(() => { | ||
task = getTask(); | ||
}); | ||
|
||
test('should add attributes to task meta', () => { | ||
const data = [ | ||
{ key: 'key1', value: 'value1' }, | ||
{ key: 'key2', value: 'value2' }, | ||
]; | ||
ReportingApi.attributes(task, data); | ||
|
||
expect((task.meta as RPTaskMeta).rpMeta.test.attributes).toEqual(data); | ||
}); | ||
|
||
test('should append attributes to existing attributes in task meta', () => { | ||
const existingAttributes = [{ key: 'existingKey', value: 'existingValue' }]; | ||
const rpMeta: RPTaskMeta = { | ||
rpMeta: { | ||
test: { | ||
logs: [], | ||
attributes: existingAttributes, | ||
}, | ||
}, | ||
}; | ||
task.meta = rpMeta; | ||
const newAttributes = [{ key: 'newKey', value: 'newValue' }]; | ||
ReportingApi.attributes(task, newAttributes); | ||
|
||
expect((task.meta as RPTaskMeta).rpMeta.test.attributes).toEqual([ | ||
...existingAttributes, | ||
...newAttributes, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ReportingApi } from '../reportingApi'; | ||
import * as vitest from 'vitest'; | ||
import { getTask } from './mocks/data'; | ||
import { RPTaskMeta } from '../models'; | ||
|
||
describe('test description reporting', () => { | ||
let task: vitest.Task; | ||
|
||
beforeEach(() => { | ||
task = getTask(); | ||
}); | ||
|
||
test('should add description to task meta', () => { | ||
const description = 'test description'; | ||
ReportingApi.description(task, description); | ||
|
||
expect((task.meta as RPTaskMeta).rpMeta.test.description).toEqual(description); | ||
}); | ||
|
||
test('should append data to existing description in task meta', () => { | ||
const existingDescription = 'test description'; | ||
const rpMeta: RPTaskMeta = { | ||
rpMeta: { | ||
test: { | ||
logs: [], | ||
attributes: [], | ||
description: existingDescription, | ||
}, | ||
}, | ||
}; | ||
task.meta = rpMeta; | ||
const newDescription = 'new test description'; | ||
ReportingApi.description(task, newDescription); | ||
|
||
expect((task.meta as RPTaskMeta).rpMeta.test.description).toEqual( | ||
existingDescription + '\n' + newDescription, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ReportPortalConfig } from '../../models'; | ||
|
||
const mockedDate = Date.now(); | ||
export class RPClientMock { | ||
private config: ReportPortalConfig; | ||
|
||
constructor(config?: ReportPortalConfig) { | ||
this.config = config; | ||
} | ||
|
||
public startLaunch = jest.fn().mockReturnValue({ | ||
promise: Promise.resolve('ok'), | ||
tempId: 'tempLaunchId', | ||
}); | ||
|
||
public finishLaunch = jest.fn().mockReturnValue({ | ||
promise: Promise.resolve('ok'), | ||
}); | ||
|
||
public startTestItem = jest.fn().mockReturnValue({ | ||
promise: Promise.resolve('ok'), | ||
tempId: 'tempTestItemId', | ||
}); | ||
|
||
public finishTestItem = jest.fn().mockReturnValue({ | ||
promise: Promise.resolve('ok'), | ||
}); | ||
|
||
public sendLog = jest.fn().mockReturnValue({ | ||
promise: Promise.resolve('ok'), | ||
}); | ||
|
||
public helpers = { | ||
now: (): number => mockedDate, | ||
}; | ||
|
||
public checkConnect = jest.fn().mockReturnValue({ | ||
promise: Promise.resolve('ok'), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ReportPortalConfig } from '../../models'; | ||
|
||
export const config: ReportPortalConfig = { | ||
apiKey: 'reportportalApiKey', | ||
endpoint: 'https://reportportal.server/api/v1', | ||
project: 'ProjectName', | ||
launch: 'LaunchName', | ||
description: 'Launch description', | ||
attributes: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as vitest from 'vitest'; | ||
|
||
export function getTask(): vitest.Task { | ||
return { | ||
id: 'id', | ||
name: 'task', | ||
type: 'suite', | ||
mode: 'run', | ||
tasks: [], | ||
meta: {}, | ||
projectName: 'testProject', | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { RPReporter } from '../reporter'; | ||
import { config } from './mocks/configMock'; | ||
import { RPClientMock } from './mocks/RPClientMock'; | ||
import * as vitest from 'vitest'; | ||
import { RPTaskMeta } from '../models'; | ||
import { STATUSES, TASK_STATUS } from '../constants'; | ||
|
||
describe('onTaskUpdate', () => { | ||
let reporter: RPReporter; | ||
const testTaskId = 'testTaskId'; | ||
const testItemId = 'testId'; | ||
beforeEach(() => { | ||
reporter = new RPReporter(config); | ||
reporter.client = new RPClientMock(config); | ||
reporter.launchId = 'tempLaunchId'; | ||
reporter.testItems.set(testTaskId, { | ||
id: testItemId, | ||
}); | ||
}); | ||
|
||
describe('finishing test with attributes, testCaseId, description in rpMeta ', () => { | ||
it('test with attributes, description, testCaseId', () => { | ||
const attributes = [ | ||
{ | ||
key: 'key1', | ||
value: 'value1', | ||
}, | ||
]; | ||
const description = 'test_description'; | ||
const testCaseId = 'testCaseId'; | ||
const taskMeta: RPTaskMeta = { | ||
rpMeta: { | ||
test: { | ||
logs: [], | ||
attributes, | ||
description, | ||
testCaseId, | ||
}, | ||
}, | ||
}; | ||
const packs: vitest.TaskResultPack[] = [[testTaskId, { state: TASK_STATUS.pass }, taskMeta]]; | ||
const finishTestItemRQ = { | ||
status: STATUSES.PASSED, | ||
attributes, | ||
description, | ||
testCaseId, | ||
endTime: reporter.client.helpers.now(), | ||
}; | ||
|
||
reporter.onTaskUpdate(packs); | ||
|
||
expect(reporter.client.finishTestItem).toBeCalledTimes(1); | ||
expect(reporter.client.finishTestItem).toBeCalledWith(testItemId, finishTestItemRQ); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ReportingApi } from '../reportingApi'; | ||
import * as vitest from 'vitest'; | ||
import { getTask } from './mocks/data'; | ||
import { RPTaskMeta } from '../models'; | ||
|
||
describe('test case id reporting', () => { | ||
let task: vitest.Task; | ||
|
||
beforeEach(() => { | ||
task = getTask(); | ||
}); | ||
|
||
test('should set test case id to task meta', () => { | ||
const testCaseId = 'test_case_id'; | ||
ReportingApi.testCaseId(task, testCaseId); | ||
|
||
expect((task.meta as RPTaskMeta).rpMeta.test.testCaseId).toEqual(testCaseId); | ||
}); | ||
|
||
test('should overwrite test case id in task meta', () => { | ||
const rpMeta: RPTaskMeta = { | ||
rpMeta: { | ||
test: { | ||
logs: [], | ||
attributes: [], | ||
testCaseId: 'old_test_case_id', | ||
}, | ||
}, | ||
}; | ||
task.meta = rpMeta; | ||
const newTestCaseId = 'new_test_case_id'; | ||
ReportingApi.testCaseId(task, newTestCaseId); | ||
|
||
expect((task.meta as RPTaskMeta).rpMeta.test.testCaseId).toEqual(newTestCaseId); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters