From 4b276b603aff03b8027192747208249ea9c562b3 Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Tue, 8 Feb 2022 23:00:54 +0530 Subject: [PATCH 1/9] added support for TAS application --- services/tas/tas-build.service.js | 61 +++++++++++++++++++++++++++++++ services/tas/tas-build.tester.js | 8 ++++ 2 files changed, 69 insertions(+) create mode 100644 services/tas/tas-build.service.js create mode 100644 services/tas/tas-build.tester.js diff --git a/services/tas/tas-build.service.js b/services/tas/tas-build.service.js new file mode 100644 index 0000000000000..9139556ad3de0 --- /dev/null +++ b/services/tas/tas-build.service.js @@ -0,0 +1,61 @@ +import Joi from 'joi' +import { BaseJsonService } from '../index.js' + +const schema = Joi.object({ + badge: Joi.object({ + status: Joi.string().required(), + duration: Joi.string().required(), + total_tests: Joi.string().required(), + }), +}).required() + +export default class TasBuildStatus extends BaseJsonService { + static category = 'build' + + static route = { + base: 'tas/build', + pattern: ':provider/:org/:repo', + } + + static examples = [ + { + title: 'TAS Build', + namedParams: { provider: 'github', org: 'lambdatest', repo: 'synapse' }, + staticPreview: this.render({ + testExecuted: '54', + duration: '2m', + status: 'passing', + }), + }, + ] + + static defaultBadgeData = { label: 'TAS' } + + static render({ testExecuted, duration, status }) { + const message = `${testExecuted} tests | Executed in ${duration}` + const color = status === 'passed' ? 'brightgreen' : 'red' + return { + message, + color, + } + } + + async fetch({ provider, org, repo }) { + return this._requestJson({ + schema, + url: `https://stage-api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, + errorMessages: { + 401: 'private application not supported', + 404: 'application not found', + }, + }) + } + + async handle({ provider, org, repo }) { + const { badge } = await this.fetch({ provider, org, repo }) + const status = badge.status + const testExecuted = badge.total_tests + const duration = badge.duration + return this.constructor.render({ testExecuted, duration, status }) + } +} diff --git a/services/tas/tas-build.tester.js b/services/tas/tas-build.tester.js new file mode 100644 index 0000000000000..cf14e20825c28 --- /dev/null +++ b/services/tas/tas-build.tester.js @@ -0,0 +1,8 @@ +import Joi from 'joi' +import { createServiceTester } from '../tester.js' +export const t = await createServiceTester() + +t.create('tas build').get('/github/nexe/nexe').expectBadge({ + label: 'TAS', + message: Joi.string(), +}) From c5fb71cab6375ac4285f0a6a9eb178938007d598 Mon Sep 17 00:00:00 2001 From: Saurabh Prakash Date: Mon, 14 Feb 2022 16:27:29 +0530 Subject: [PATCH 2/9] Added prod url. Fixed test-case --- services/tas/tas-build.service.js | 2 +- services/tas/tas-build.tester.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/tas/tas-build.service.js b/services/tas/tas-build.service.js index 9139556ad3de0..37d3a8c4363d8 100644 --- a/services/tas/tas-build.service.js +++ b/services/tas/tas-build.service.js @@ -43,7 +43,7 @@ export default class TasBuildStatus extends BaseJsonService { async fetch({ provider, org, repo }) { return this._requestJson({ schema, - url: `https://stage-api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, + url: `https://api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, errorMessages: { 401: 'private application not supported', 404: 'application not found', diff --git a/services/tas/tas-build.tester.js b/services/tas/tas-build.tester.js index cf14e20825c28..be39d4d611974 100644 --- a/services/tas/tas-build.tester.js +++ b/services/tas/tas-build.tester.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { createServiceTester } from '../tester.js' export const t = await createServiceTester() -t.create('tas build').get('/github/nexe/nexe').expectBadge({ +t.create('tas build').get('/github/tasdemo/axios.json').expectBadge({ label: 'TAS', message: Joi.string(), }) From cdfee73f46ac7278dd9c0e1ef5bf4b3a84e8143a Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Tue, 22 Feb 2022 19:30:07 +0530 Subject: [PATCH 3/9] fixed label --- services/tas/tas-build.service.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/tas/tas-build.service.js b/services/tas/tas-build.service.js index 37d3a8c4363d8..3a009c48be311 100644 --- a/services/tas/tas-build.service.js +++ b/services/tas/tas-build.service.js @@ -10,10 +10,10 @@ const schema = Joi.object({ }).required() export default class TasBuildStatus extends BaseJsonService { - static category = 'build' + static category = 'test-results' static route = { - base: 'tas/build', + base: 'tas/tests', pattern: ':provider/:org/:repo', } @@ -29,7 +29,7 @@ export default class TasBuildStatus extends BaseJsonService { }, ] - static defaultBadgeData = { label: 'TAS' } + static defaultBadgeData = { label: 'tests' } static render({ testExecuted, duration, status }) { const message = `${testExecuted} tests | Executed in ${duration}` From 93e9dfe76fee5cbd1deba084d0721484294ee842 Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Tue, 22 Feb 2022 19:39:15 +0530 Subject: [PATCH 4/9] updated tests --- services/tas/tas-build.tester.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/tas/tas-build.tester.js b/services/tas/tas-build.tester.js index be39d4d611974..35c715ffaffc3 100644 --- a/services/tas/tas-build.tester.js +++ b/services/tas/tas-build.tester.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { createServiceTester } from '../tester.js' export const t = await createServiceTester() -t.create('tas build').get('/github/tasdemo/axios.json').expectBadge({ - label: 'TAS', +t.create('tas tests').get('/github/tasdemo/axios.json').expectBadge({ + label: 'tests', message: Joi.string(), }) From f56a2b573ffbad43610fe147b0ebec55f75f6018 Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Thu, 24 Feb 2022 16:52:42 +0530 Subject: [PATCH 5/9] streamlining of test badge --- services/tas/tas-build.service.js | 61 ---------- services/tas/tas-tests.service.js | 110 ++++++++++++++++++ ...as-build.tester.js => tas-tests.tester.js} | 0 3 files changed, 110 insertions(+), 61 deletions(-) delete mode 100644 services/tas/tas-build.service.js create mode 100644 services/tas/tas-tests.service.js rename services/tas/{tas-build.tester.js => tas-tests.tester.js} (100%) diff --git a/services/tas/tas-build.service.js b/services/tas/tas-build.service.js deleted file mode 100644 index 3a009c48be311..0000000000000 --- a/services/tas/tas-build.service.js +++ /dev/null @@ -1,61 +0,0 @@ -import Joi from 'joi' -import { BaseJsonService } from '../index.js' - -const schema = Joi.object({ - badge: Joi.object({ - status: Joi.string().required(), - duration: Joi.string().required(), - total_tests: Joi.string().required(), - }), -}).required() - -export default class TasBuildStatus extends BaseJsonService { - static category = 'test-results' - - static route = { - base: 'tas/tests', - pattern: ':provider/:org/:repo', - } - - static examples = [ - { - title: 'TAS Build', - namedParams: { provider: 'github', org: 'lambdatest', repo: 'synapse' }, - staticPreview: this.render({ - testExecuted: '54', - duration: '2m', - status: 'passing', - }), - }, - ] - - static defaultBadgeData = { label: 'tests' } - - static render({ testExecuted, duration, status }) { - const message = `${testExecuted} tests | Executed in ${duration}` - const color = status === 'passed' ? 'brightgreen' : 'red' - return { - message, - color, - } - } - - async fetch({ provider, org, repo }) { - return this._requestJson({ - schema, - url: `https://api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, - errorMessages: { - 401: 'private application not supported', - 404: 'application not found', - }, - }) - } - - async handle({ provider, org, repo }) { - const { badge } = await this.fetch({ provider, org, repo }) - const status = badge.status - const testExecuted = badge.total_tests - const duration = badge.duration - return this.constructor.render({ testExecuted, duration, status }) - } -} diff --git a/services/tas/tas-tests.service.js b/services/tas/tas-tests.service.js new file mode 100644 index 0000000000000..380ab4e967a6f --- /dev/null +++ b/services/tas/tas-tests.service.js @@ -0,0 +1,110 @@ +import Joi from 'joi' +import { BaseJsonService } from '../index.js' +import { + testResultQueryParamSchema, + renderTestResultBadge, +} from '../test-results.js' + +const commonAttrs = { + namedParams: { + provider: 'github', + org: 'test-at-scale', + repo: 'badge-demo', + }, + queryParams: { + passed_label: 'passed', + failed_label: 'failed', + skipped_label: 'skipped', + compact_message: null, + }, +} + +const schema = Joi.object({ + badge: Joi.object({ + passed: Joi.number().required(), + failed: Joi.number().required(), + skipped: Joi.number().required(), + total_tests: Joi.number().required(), + status: Joi.string().required(), + }).required(), +}).required() + +export default class TasBuildStatus extends BaseJsonService { + static category = 'test-results' + + static route = { + base: 'tas/tests', + pattern: ':provider/:org/:repo', + queryParamSchema: testResultQueryParamSchema, + } + + static examples = [ + { + title: 'TAS Tests', + staticPreview: this.render({ + passed: 20, + failed: 1, + skipped: 1, + total: 22, + }), + ...commonAttrs, + }, + ] + + static defaultBadgeData = { label: 'tests' } + + static render({ + passed, + failed, + skipped, + total, + passedLabel, + failedLabel, + skippedLabel, + isCompact, + }) { + return renderTestResultBadge({ + passed, + failed, + skipped, + total, + passedLabel, + failedLabel, + skippedLabel, + isCompact, + }) + } + + async fetch({ provider, org, repo }) { + return this._requestJson({ + schema, + url: `https://api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, + errorMessages: { + 401: 'private application not supported', + 404: 'application not found', + }, + }) + } + + async handle( + { provider, org, repo }, + { + compact_message: compactMessage, + passed_label: passedLabel, + failed_label: failedLabel, + skipped_label: skippedLabel, + } + ) { + const { badge } = await this.fetch({ provider, org, repo }) + return this.constructor.render({ + passed: badge.passed, + failed: badge.failed, + skipped: badge.skipped, + total: badge.total_tests, + passedLabel, + failedLabel, + skippedLabel, + isCompact: compactMessage !== undefined, + }) + } +} diff --git a/services/tas/tas-build.tester.js b/services/tas/tas-tests.tester.js similarity index 100% rename from services/tas/tas-build.tester.js rename to services/tas/tas-tests.tester.js From 070d737f0963036572b68634d107f427543f1eab Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Mon, 28 Feb 2022 17:35:23 +0530 Subject: [PATCH 6/9] mock test cases --- services/tas/tas-tests.service.js | 4 +- services/tas/tas-tests.tester.js | 91 +++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/services/tas/tas-tests.service.js b/services/tas/tas-tests.service.js index 380ab4e967a6f..fa25932a4216b 100644 --- a/services/tas/tas-tests.service.js +++ b/services/tas/tas-tests.service.js @@ -80,8 +80,8 @@ export default class TasBuildStatus extends BaseJsonService { schema, url: `https://api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, errorMessages: { - 401: 'private application not supported', - 404: 'application not found', + 401: 'private project not supported', + 404: 'project not found', }, }) } diff --git a/services/tas/tas-tests.tester.js b/services/tas/tas-tests.tester.js index 35c715ffaffc3..3bb1067c29da8 100644 --- a/services/tas/tas-tests.tester.js +++ b/services/tas/tas-tests.tester.js @@ -1,8 +1,89 @@ -import Joi from 'joi' import { createServiceTester } from '../tester.js' +import { + isDefaultTestTotals, + isCustomTestTotals, + isCustomCompactTestTotals, +} from '../test-validators.js' + export const t = await createServiceTester() -t.create('tas tests').get('/github/tasdemo/axios.json').expectBadge({ - label: 'tests', - message: Joi.string(), -}) +const tasBaseUri = `https://api.tas.lambdatest.com/repo/badge` + +const mockStat = { + badge: { + status: 'passed', + total_tests: 40, + passed: 36, + failed: 1, + skipped: 2, + }, +} + +t.create('Test status') + .get('/github/tasdemo/demo.json') + .intercept(nock => + nock(tasBaseUri) + .get('?git_provider=github&org=tasdemo&repo=demo') + .reply(200, mockStat) + ) + .expectBadge({ label: 'tests', message: isDefaultTestTotals }) + +t.create('Test status with custom labels') + .get('/github/tasdemo/demo.json', { + qs: { + passed_label: 'good', + failed_label: 'bad', + skipped_label: 'n/a', + }, + }) + .intercept(nock => + nock(tasBaseUri) + .get('?git_provider=github&org=tasdemo&repo=demo') + .reply(200, mockStat) + ) + .expectBadge({ label: 'tests', message: isCustomTestTotals }) + +t.create('Test status with compact message and custom labels') + .get('/github/tasdemo/demo.json', { + qs: { + compact_message: null, + passed_label: '💃', + failed_label: '🤦‍♀️', + skipped_label: '🤷', + }, + }) + .intercept(nock => + nock(tasBaseUri) + .get('?git_provider=github&org=tasdemo&repo=demo') + .reply(200, mockStat) + ) + .expectBadge({ + label: 'tests', + message: isCustomCompactTestTotals, + }) + +t.create('Test status on project that does not exist') + .get('/github/tasdemo/doesntexist.json') + .intercept(nock => + nock(tasBaseUri) + .get('?git_provider=github&org=tasdemo&repo=doesntexist') + .reply(404, {}) + ) + .expectBadge({ + label: 'tests', + message: 'project not found', + color: 'red', + }) + +t.create('Test status on private project') + .get('/github/tasdemo/private.json') + .intercept(nock => + nock(tasBaseUri) + .get('?git_provider=github&org=tasdemo&repo=private') + .reply(401, {}) + ) + .expectBadge({ + label: 'tests', + message: 'private project not supported', + color: 'lightgrey', + }) From 8260f9e6365cf2699b8169d453fd2b6e5224ac62 Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Thu, 3 Mar 2022 16:52:20 +0530 Subject: [PATCH 7/9] updated tests to make it live --- services/tas/tas-tests.tester.js | 45 +++----------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/services/tas/tas-tests.tester.js b/services/tas/tas-tests.tester.js index 3bb1067c29da8..8c95555daf25c 100644 --- a/services/tas/tas-tests.tester.js +++ b/services/tas/tas-tests.tester.js @@ -7,44 +7,22 @@ import { export const t = await createServiceTester() -const tasBaseUri = `https://api.tas.lambdatest.com/repo/badge` - -const mockStat = { - badge: { - status: 'passed', - total_tests: 40, - passed: 36, - failed: 1, - skipped: 2, - }, -} - t.create('Test status') - .get('/github/tasdemo/demo.json') - .intercept(nock => - nock(tasBaseUri) - .get('?git_provider=github&org=tasdemo&repo=demo') - .reply(200, mockStat) - ) + .get('/github/tasdemo/axios.json') .expectBadge({ label: 'tests', message: isDefaultTestTotals }) t.create('Test status with custom labels') - .get('/github/tasdemo/demo.json', { + .get('/github/tasdemo/axios.json', { qs: { passed_label: 'good', failed_label: 'bad', skipped_label: 'n/a', }, }) - .intercept(nock => - nock(tasBaseUri) - .get('?git_provider=github&org=tasdemo&repo=demo') - .reply(200, mockStat) - ) .expectBadge({ label: 'tests', message: isCustomTestTotals }) t.create('Test status with compact message and custom labels') - .get('/github/tasdemo/demo.json', { + .get('/github/tasdemo/axios.json', { qs: { compact_message: null, passed_label: '💃', @@ -52,11 +30,6 @@ t.create('Test status with compact message and custom labels') skipped_label: '🤷', }, }) - .intercept(nock => - nock(tasBaseUri) - .get('?git_provider=github&org=tasdemo&repo=demo') - .reply(200, mockStat) - ) .expectBadge({ label: 'tests', message: isCustomCompactTestTotals, @@ -64,11 +37,6 @@ t.create('Test status with compact message and custom labels') t.create('Test status on project that does not exist') .get('/github/tasdemo/doesntexist.json') - .intercept(nock => - nock(tasBaseUri) - .get('?git_provider=github&org=tasdemo&repo=doesntexist') - .reply(404, {}) - ) .expectBadge({ label: 'tests', message: 'project not found', @@ -76,12 +44,7 @@ t.create('Test status on project that does not exist') }) t.create('Test status on private project') - .get('/github/tasdemo/private.json') - .intercept(nock => - nock(tasBaseUri) - .get('?git_provider=github&org=tasdemo&repo=private') - .reply(401, {}) - ) + .get('/github/tasdemo/nexe-private.json') .expectBadge({ label: 'tests', message: 'private project not supported', From f0d21460af39a64086af0a94b2afdb44824d0705 Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Thu, 3 Mar 2022 16:59:37 +0530 Subject: [PATCH 8/9] updated schema validation --- services/tas/tas-tests.service.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/tas/tas-tests.service.js b/services/tas/tas-tests.service.js index fa25932a4216b..9718cdb8ce295 100644 --- a/services/tas/tas-tests.service.js +++ b/services/tas/tas-tests.service.js @@ -4,6 +4,7 @@ import { testResultQueryParamSchema, renderTestResultBadge, } from '../test-results.js' +import { nonNegativeInteger } from '../../services/validators.js' const commonAttrs = { namedParams: { @@ -21,10 +22,10 @@ const commonAttrs = { const schema = Joi.object({ badge: Joi.object({ - passed: Joi.number().required(), - failed: Joi.number().required(), - skipped: Joi.number().required(), - total_tests: Joi.number().required(), + passed: nonNegativeInteger, + failed: nonNegativeInteger, + skipped: nonNegativeInteger, + total_tests: nonNegativeInteger, status: Joi.string().required(), }).required(), }).required() From 810236e6d11d0d9c9cbc85e7d290260351769fb0 Mon Sep 17 00:00:00 2001 From: Nevil Macwan Date: Fri, 4 Mar 2022 11:10:39 +0530 Subject: [PATCH 9/9] updated example --- services/tas/tas-tests.service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/tas/tas-tests.service.js b/services/tas/tas-tests.service.js index 9718cdb8ce295..b347f8caaacd8 100644 --- a/services/tas/tas-tests.service.js +++ b/services/tas/tas-tests.service.js @@ -9,8 +9,8 @@ import { nonNegativeInteger } from '../../services/validators.js' const commonAttrs = { namedParams: { provider: 'github', - org: 'test-at-scale', - repo: 'badge-demo', + org: 'tasdemo', + repo: 'axios', }, queryParams: { passed_label: 'passed',