Skip to content

Commit

Permalink
Merge pull request clearlydefined#106 from qtomlinson/qt/fix_components
Browse files Browse the repository at this point in the history
Fix integration tests
  • Loading branch information
elrayle authored Oct 28, 2024
2 parents dee931e + 3701bf2 commit c10f84f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ const { callFetch } = require('../../../lib/fetch')
const { devApiBaseUrl, prodApiBaseUrl, getComponents, definition } = require('../testConfig')
const { strictEqual } = require('assert')

describe('Validation attachments between dev and prod', async function () {
this.timeout(definition.timeout * 2)
;(async function () {
const components = await getComponents()
describe('Validation attachments between dev and prod', async function () {
this.timeout(definition.timeout * 2)

//Rest a bit to avoid overloading the servers
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2)))
//Rest a bit to avoid overloading the servers
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2)))

const components = await getComponents()
components.forEach(coordinates => {
it(`should have the same attachement as prod for ${coordinates}`, () => fetchAndCompareAttachments(coordinates))
components.forEach(coordinates => {
it(`should have the same attachement as prod for ${coordinates}`, () => fetchAndCompareAttachments(coordinates))
})
})
})
})()

async function fetchAndCompareAttachments(coordinates) {
const expectedAttachments = await findAttachments(prodApiBaseUrl, coordinates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,61 @@ const { devApiBaseUrl, prodApiBaseUrl, getComponents, definition } = require('..
const nock = require('nock')
const fs = require('fs')

describe('Validate definitions', function () {
this.timeout(definition.timeout)

//Rest a bit to avoid overloading the servers
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2)))

describe('Validation between dev and prod', async function () {
before(() => {
loadFixtures().forEach(([url, definition]) => {
nock(prodApiBaseUrl, { allowUnmocked: true }).get(url).reply(200, definition)
;(async function () {
const components = await getComponents()
describe('Validate definitions', function () {
this.timeout(definition.timeout)

//Rest a bit to avoid overloading the servers
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2)))

describe('Validation between dev and prod', function () {
before(() => {
loadFixtures().forEach(([url, definition]) => {
nock(prodApiBaseUrl, { allowUnmocked: true }).get(url).reply(200, definition)
})
})
console.info(`Testing definitions for ${JSON.stringify(components)}`)
components.forEach(coordinates => {
it(`should return the same definition as prod for ${coordinates}`, () => fetchAndCompareDefinition(coordinates))
})
})
const components = await getComponents()
console.info(`Testing definitions for ${JSON.stringify(components)}`)
components.forEach(coordinates => {
it(`should return the same definition as prod for ${coordinates}`, () => fetchAndCompareDefinition(coordinates))
})
})

describe('Validate on dev', async function () {
const components = await getComponents()
const coordinates = components[0]

describe('Search definitions', function () {
it(`should find definition for ${coordinates}`, async function () {
const [foundDef, expectedDef] = await Promise.all([
findDefinition(coordinates),
getDefinition(devApiBaseUrl, coordinates)
])
deepStrictEqualExpectedEntries(foundDef, omit(expectedDef, ['files']))
describe('Validate on dev', function () {
const coordinates = components[0]

describe('Search definitions', function () {
it(`should find definition for ${coordinates}`, async function () {
const [foundDef, expectedDef] = await Promise.all([
findDefinition(coordinates),
getDefinition(devApiBaseUrl, coordinates)
])
deepStrictEqualExpectedEntries(foundDef, omit(expectedDef, ['files']))
})
})
})

describe('Search coordinates via pattern', function () {
it(`should find coordinates for aws-sdk-java`, async function () {
const response = await callFetch(`${devApiBaseUrl}/definitions?pattern=aws-sdk-java`).then(r => r.json())
ok(response.length > 0)
describe('Search coordinates via pattern', function () {
it(`should find coordinates for aws-sdk-java`, async function () {
const response = await callFetch(`${devApiBaseUrl}/definitions?pattern=aws-sdk-java`).then(r => r.json())
ok(response.length > 0)
})
})
})

describe('Post to /definitions', function () {
it(`should get definition via post to /definitions for ${coordinates}`, async function () {
const postDefinitions = callFetch(`${devApiBaseUrl}/definitions`, buildPostOpts([coordinates])).then(r =>
r.json()
)
const [actualDef, expectedDef] = await Promise.all([
postDefinitions.then(r => r[coordinates]),
getDefinition(devApiBaseUrl, coordinates)
])
deepStrictEqualExpectedEntries(actualDef, expectedDef)
describe('Post to /definitions', function () {
it(`should get definition via post to /definitions for ${coordinates}`, async function () {
const postDefinitions = callFetch(`${devApiBaseUrl}/definitions`, buildPostOpts([coordinates])).then(r =>
r.json()
)
const [actualDef, expectedDef] = await Promise.all([
postDefinitions.then(r => r[coordinates]),
getDefinition(devApiBaseUrl, coordinates)
])
deepStrictEqualExpectedEntries(actualDef, expectedDef)
})
})
})
})
})
})()

async function fetchAndCompareDefinition(coordinates) {
const [recomputedDef, expectedDef] = await Promise.all([
Expand Down
30 changes: 16 additions & 14 deletions tools/integration/test/integration/e2e-test-service/noticeTest.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ const { devApiBaseUrl, prodApiBaseUrl, getComponents, definition } = require('..
const nock = require('nock')
const fs = require('fs')

describe('Validate notice files between dev and prod', async function () {
this.timeout(definition.timeout)
;(async function () {
const components = await getComponents()
describe('Validate notice files between dev and prod', async function () {
this.timeout(definition.timeout)

//Rest a bit to avoid overloading the servers
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2)))
//Rest a bit to avoid overloading the servers
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2)))

before(() => {
loadFixtures().forEach(([coordinatesString, notice]) => {
nock(prodApiBaseUrl, { allowUnmocked: true })
.post('/notices', { coordinates: [coordinatesString] })
.reply(200, notice)
before(() => {
loadFixtures().forEach(([coordinatesString, notice]) => {
nock(prodApiBaseUrl, { allowUnmocked: true })
.post('/notices', { coordinates: [coordinatesString] })
.reply(200, notice)
})
})
components.forEach(coordinates => {
it(`should return the same notice as prod for ${coordinates}`, () => fetchAndCompareNotices(coordinates))
})
})
const components = await getComponents()
components.forEach(coordinates => {
it(`should return the same notice as prod for ${coordinates}`, () => fetchAndCompareNotices(coordinates))
})
})
})()

async function fetchAndCompareNotices(coordinates) {
const [computedNotice, expectedNotice] = await Promise.all(
Expand Down

0 comments on commit c10f84f

Please sign in to comment.