Skip to content

Commit

Permalink
Merge pull request #20 from bun913/feat/add-test-case
Browse files Browse the repository at this point in the history
feat/add test case
  • Loading branch information
bun913 authored Aug 27, 2024
2 parents 0f5ba8e + 4927149 commit 1141299
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/TestrailReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const requiredOptions = ["domain", "username", "apikey", "projectId"]
class TestRailReporter {
constructor(emitter, reporterOptions, options) {
this.results = []
this.testRailApi = new TestRailApi(request)
emitter.on("beforeDone", (err, args) => {
this.onComplete(err, args)
})
Expand Down Expand Up @@ -43,7 +44,7 @@ class TestRailReporter {
// If we're matching by full title, transform the names to use C123 titles
// so we don't have to modify follow up code
if (this.env.useTitles.toLowerCase() === "true") {
const testRailApi = new TestRailApi(request)
const testRailApi = this.testRailApi
const allCases = testRailApi.getCases()

filteredExecutions.forEach((execution) => {
Expand Down Expand Up @@ -201,7 +202,7 @@ class TestRailReporter {

pushToTestrail(summary) {
if (this.results.length > 0) {
const testRailApi = new TestRailApi(request)
const testRailApi = this.testRailApi
// TODO: not repeatable use responce variable
let response

Expand Down
43 changes: 43 additions & 0 deletions test/TestrailReporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,49 @@ describe("TestrailReporter", () => {
})
})

describe("User wants to establish connection by title not by case id", () => {
describe("When TESTRAIL_TITLE_MATCHING env value is `true`", () => {
it("Newman assertions with title `TestTitle` matched to TestRail test case with `TestTitle`", () => {
// arrange
setEnvVars(vi)
vi.stubEnv("TESTRAIL_TITLE_MATCHING", "true")
const sut = new TestrailReporter(makeSampleEmitter(vi.fn()), {}, {})
sut.testRailApi.getCases = vi
.fn()
.mockReturnValueOnce([{ id: 1, title: "TestTitle" }])
sut.env = getEnv()
const executions = makeNewmanResult({ assertionName: "TestTitle" })

// act
sut.jsonifyResults(executions)

// assert
expect(sut.results).lengthOf(1)
expect(sut.results[0].case_id).toBe("1")
})

it("Newman assertions with title `NoMatchedTitle` not matched to TestRail test case with `TestTitle`", () => {
// arrange
setEnvVars(vi)
vi.stubEnv("TESTRAIL_TITLE_MATCHING", "true")
const sut = new TestrailReporter(makeSampleEmitter(vi.fn()), {}, {})
sut.testRailApi.getCases = vi
.fn()
.mockReturnValueOnce([{ id: 1, title: "TestTitle" }])
sut.env = getEnv()
const executions = makeNewmanResult({
assertionName: "NoMatchedTitle",
})

// act
sut.jsonifyResults(executions)

// assert
expect(sut.results).lengthOf(0)
})
})
})

describe("test rail v1 API", () => {
it("works for TestRail v1 api", () => {
// arrange
Expand Down
7 changes: 6 additions & 1 deletion test/utils/newman.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module.exports = function makeNewmanResult({
caseNumbers = "C01",
assertionName = "",
error = false,
skipped = false,
tldOnly = false,
} = {}) {
let assertionFullName = assertionName
if (assertionName === "") {
assertionFullName = `${caseNumbers} Status code is 400`
}
const json = {
cursor: {},
item: {
Expand Down Expand Up @@ -74,7 +79,7 @@ module.exports = function makeNewmanResult({
id: "59395a21-ad0a-4baf-b452-beddb3d471a4",
assertions: [
{
assertion: `${caseNumbers} Status code is 400`,
assertion: assertionFullName,
skipped,
},
],
Expand Down

0 comments on commit 1141299

Please sign in to comment.