Skip to content

Commit

Permalink
Merge pull request #89 from qtomlinson/qt/add_status_test
Browse files Browse the repository at this point in the history
Add more integration tests for StatusService and StatsService
  • Loading branch information
qtomlinson authored Sep 24, 2024
2 parents 5d9b5a7 + f9c7892 commit ff0fdb3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT

const { omit, isEqual, pick } = require('lodash')
const { deepStrictEqual, strictEqual } = require('assert')
const { deepStrictEqual, strictEqual, ok } = require('assert')
const { callFetch, buildPostOpts } = require('../../../lib/fetch')
const { devApiBaseUrl, prodApiBaseUrl, components, definition } = require('../testConfig')
const nock = require('nock')
Expand Down Expand Up @@ -39,6 +39,13 @@ describe('Validation definitions between dev and prod', function () {
})
})

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 =>
Expand Down
50 changes: 50 additions & 0 deletions tools/integration/test/integration/e2e-test-service/statsTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const { callFetch } = require('../../../lib/fetch')
const { devApiBaseUrl, definition } = require('../testConfig')
const { ok } = require('assert')

describe('Test for StatsService', function () {
this.timeout(definition.timeout * 10)

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

it('should retrieve the list of supported stats', async function () {
const url = `${devApiBaseUrl}/stats`
const result = await callFetch(url).then(r => r.json())
const expected = [
'total',
'conda',
'condasrc',
'crate',
'gem',
'git',
'maven',
'npm',
'nuget',
'pod',
'composer',
'pypi',
'deb',
'debsrc'
]
ok(result.length === expected.length)
expected.forEach(e => ok(result.includes(e)))
})

it('should retrieve stats for total', async function () {
const url = `${devApiBaseUrl}/stats/total`
const result = await callFetch(url).then(r => r.json())
ok(result.value.totalCount > 0)
ok(result.value.declaredLicenseBreakdown)
})

it('should retrieve stats for composer', async function () {
const url = `${devApiBaseUrl}/stats/composer`
const result = await callFetch(url).then(r => r.json())
ok(result.value.totalCount > 0)
ok(result.value.declaredLicenseBreakdown)
})
})
45 changes: 45 additions & 0 deletions tools/integration/test/integration/e2e-test-service/statusTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const { callFetch } = require('../../../lib/fetch')
const { devApiBaseUrl, definition } = require('../testConfig')
const { ok } = require('assert')

describe('Test for StatusService', function () {
this.timeout(definition.timeout * 10)

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

it('should retrieve the list of supported status queries', async function () {
const url = `${devApiBaseUrl}/status`
const result = await callFetch(url).then(r => r.json())
const expected = [
'requestcount',
'definitionavailability',
'processedperday',
'recentlycrawled',
'crawlbreakdown',
'toolsranperday'
]
ok(result.length === expected.length)
expected.forEach(e => ok(result.includes(e)))
})

it('should retrieve toolsranperday status via crawler query', async function () {
const url = `${devApiBaseUrl}/status/toolsranperday`
const result = await callFetch(url).then(r => r.json())
ok(result.length > 0)
ok(result[0].clearlydefined > 0 || result[0].licensee > 0 || result[0].reuse > 0 || result[0].scancode > 0)
})

it('should retrieve requestCount status (including today) via service query', async function () {
const url = `${devApiBaseUrl}/status/requestCount`
const result = await callFetch(url).then(r => r.json())
const sortedDates = Object.keys(result).sort((a, b) => b.localeCompare(a))
ok(sortedDates.length > 0)
const mostRecentDate = sortedDates[0]
const today = new Date().toISOString().split('T')[0]
ok(mostRecentDate.includes(today))
})
})

0 comments on commit ff0fdb3

Please sign in to comment.