From f9c7892510e3f00436553eaf3816381cc8a104d3 Mon Sep 17 00:00:00 2001 From: Qing Tomlinson Date: Thu, 15 Aug 2024 17:04:22 -0700 Subject: [PATCH] Add more integration tests for StatusService and StatsService The tests added are to test the integration with AzureSearch and ApplicationInsight --- .../e2e-test-service/definitionTest.js | 9 +++- .../integration/e2e-test-service/statsTest.js | 50 +++++++++++++++++++ .../e2e-test-service/statusTest.js | 45 +++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tools/integration/test/integration/e2e-test-service/statsTest.js create mode 100644 tools/integration/test/integration/e2e-test-service/statusTest.js diff --git a/tools/integration/test/integration/e2e-test-service/definitionTest.js b/tools/integration/test/integration/e2e-test-service/definitionTest.js index 7623565..a5fdd79 100644 --- a/tools/integration/test/integration/e2e-test-service/definitionTest.js +++ b/tools/integration/test/integration/e2e-test-service/definitionTest.js @@ -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') @@ -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 => diff --git a/tools/integration/test/integration/e2e-test-service/statsTest.js b/tools/integration/test/integration/e2e-test-service/statsTest.js new file mode 100644 index 0000000..0ddd7a9 --- /dev/null +++ b/tools/integration/test/integration/e2e-test-service/statsTest.js @@ -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) + }) +}) diff --git a/tools/integration/test/integration/e2e-test-service/statusTest.js b/tools/integration/test/integration/e2e-test-service/statusTest.js new file mode 100644 index 0000000..77600e1 --- /dev/null +++ b/tools/integration/test/integration/e2e-test-service/statusTest.js @@ -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)) + }) +})