Skip to content

Commit

Permalink
Refactor TeamCity auth tests for use of testAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
jNullj committed Mar 22, 2024
1 parent a2b5331 commit 87c68e2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 79 deletions.
43 changes: 10 additions & 33 deletions services/teamcity/teamcity-build.spec.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,16 @@
import { expect } from 'chai'
import nock from 'nock'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import { testAuth } from '../test-helpers.js'
import TeamCityBuild from './teamcity-build.service.js'
import { user, pass, host, config } from './teamcity-test-helpers.js'
import { config } from './teamcity-test-helpers.js'

describe('TeamCityBuild', function () {
cleanUpNockAfterEach()

it('sends the auth information as configured', async function () {
const scope = nock(`https://${host}`)
.get(`/app/rest/builds/${encodeURIComponent('buildType:(id:bt678)')}`)
// This ensures that the expected credentials are actually being sent with the HTTP request.
// Without this the request wouldn't match and the test would fail.
.basicAuth({ user, pass })
.reply(200, {
status: 'FAILURE',
statusText:
'Tests failed: 1 (1 new), passed: 50246, ignored: 1, muted: 12',
})

expect(
await TeamCityBuild.invoke(
defaultContext,
config,
{
verbosity: 'e',
buildId: 'bt678',
},
{ server: `https://${host}` },
),
).to.deep.equal({
message: 'tests failed: 1 (1 new), passed: 50246, ignored: 1, muted: 12',
color: 'red',
describe('auth', function () {
it('sends the auth information as configured', async function () {
testAuth(
TeamCityBuild,
'BasicAuth',
{ status: 'SUCCESS', statusText: 'Success' },
{ configOverride: config },
)
})

scope.done()
})
})
49 changes: 13 additions & 36 deletions services/teamcity/teamcity-coverage.spec.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,21 @@
import { expect } from 'chai'
import nock from 'nock'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import { testAuth } from '../test-helpers.js'
import TeamCityCoverage from './teamcity-coverage.service.js'
import { user, pass, host, config } from './teamcity-test-helpers.js'
import { config } from './teamcity-test-helpers.js'

describe('TeamCityCoverage', function () {
cleanUpNockAfterEach()

it('sends the auth information as configured', async function () {
const scope = nock(`https://${host}`)
.get(
`/app/rest/builds/${encodeURIComponent(
'buildType:(id:bt678)',
)}/statistics`,
)
.query({})
// This ensures that the expected credentials are actually being sent with the HTTP request.
// Without this the request wouldn't match and the test would fail.
.basicAuth({ user, pass })
.reply(200, {
property: [
{ name: 'CodeCoverageAbsSCovered', value: '82' },
{ name: 'CodeCoverageAbsSTotal', value: '100' },
],
})

expect(
await TeamCityCoverage.invoke(
defaultContext,
config,
describe('auth', function () {
it('sends the auth information as configured', async function () {
testAuth(
TeamCityCoverage,
'BasicAuth',
{
buildId: 'bt678',
property: [
{ name: 'CodeCoverageAbsSCovered', value: '93' },
{ name: 'CodeCoverageAbsSTotal', value: '95' },
],
},
{ server: 'https://mycompany.teamcity.com' },
),
).to.deep.equal({
message: '82%',
color: 'yellowgreen',
{ configOverride: config },
)
})

scope.done()
})
})
15 changes: 5 additions & 10 deletions services/teamcity/teamcity-test-helpers.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
const user = 'admin'
const pass = 'password'
const host = 'mycompany.teamcity.com'
import TeamCityBase from './teamcity-base.js'

const config = {
public: {
services: {
teamcity: {
authorizedOrigins: [`https://${host}`],
[TeamCityBase.auth.serviceKey]: {
authorizedOrigins: ['https://teamcity.jetbrains.com'],
},
},
},
private: {
teamcity_user: user,
teamcity_pass: pass,
},
}

export { user, pass, host, config }
export { config }

0 comments on commit 87c68e2

Please sign in to comment.