diff --git a/scripts/healthcheck.bash b/scripts/healthcheck.bash index 3f4ee56..3d193f1 100755 --- a/scripts/healthcheck.bash +++ b/scripts/healthcheck.bash @@ -1,16 +1,4 @@ #!/bin/bash -#set -eux -# -#wait-for-status() { -# echo "Waiting for services status" -# echo "" -# bash -c \ -# 'while [[ "$(npm run status)" == *"(starting)"* ]];\ -# do echo "Waiting for services" && sleep 30;\ -# done' -#} -#wait-for-status - while true; do # Run the command and capture the output output=$(npm run status) diff --git a/src/uat.js b/src/api-testing-client.js similarity index 84% rename from src/uat.js rename to src/api-testing-client.js index 5cd2577..3300d09 100644 --- a/src/uat.js +++ b/src/api-testing-client.js @@ -1,6 +1,6 @@ const axios = require('axios'); -class UAT { +class ApiTestingClient { constructor (options) { this.baseURL = `${options.protocol}://${options.domain}${options.apiPath}`; this.token = options.token; @@ -70,32 +70,12 @@ class UAT { } /** - * Generating an API token - * @param {*} token The UI token to authenticate with - * @returns A response obj with the API token data + * We create an API key to use it later on in our tests. + * @param {*} token + * @param {*} userId + * @param {*} name + * @returns */ - async generateApiToken(token) { - this.setApiToken(token); - try { - const response = await this.client.post('uat/sso/me/apitoken?authenticated=true'); - return this.handleResponse(response); - } - catch(error) { - return this.handleError(error); - } - } - - async getApiKeys(token, userId) { - try { - this.setApiToken(token); - const response = await this.client.get(`uat/api/users/${userId}/api-keys`); - return this.handleResponse(response).items; - } - catch (error) { - return this.handleError(error); - } - } - async createApiToken(token, userId, name) { try { this.setApiToken(token); @@ -172,4 +152,4 @@ class UAT { } } -module.exports = UAT; +module.exports = ApiTestingClient; diff --git a/src/index.js b/src/index.js index b1d9037..4344421 100644 --- a/src/index.js +++ b/src/index.js @@ -77,14 +77,14 @@ exports['default'] = () => { }, async reportLogs(testId, level, message, time, attachment) { if(message !== undefined) { - const isJSON = this.reporter.client.isJSON(message) || Array.isArray(message); - const isException = isJSON && JSON.parse(message).errMsg !== undefined; + const isJSON = (msg) => { return this.reporter.client.isJSON(msg) || Array.isArray(msg); } + const isException = isJSON(message) && JSON.parse(message).errMsg !== undefined; //If the log is a stacktrace, and we want to focus on printing the error message itself. if(isException) message = JSON.parse(message).errMsg; //If the log is a JS Object - else if(isJSON) message = JSON.parse(message); + else if(isJSON(message)) message = JSON.parse(message); else if(typeof message === 'object') message = `"${message}"`; - message = isJSON ? JSON.stringify(message): message; + message = isJSON(message) ? JSON.stringify(message): message; } await this.reporter.sendTestLogs(testId, level, message, time, attachment); }, diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index c11e4ad..f18f3ee 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -2,23 +2,22 @@ import { loadArguments } from '../utils/cli-loader'; import createTestCafe from 'testcafe'; import { cliArguments } from 'cli-argument-parser'; import { expect } from 'chai'; -import UAT from '../../src/uat.js' +import ApiTestingClient from '../../src/api-testing-client.js' let testcafeServer: TestCafe; describe('Performing Integration testing', async function() { this.timeout(10 * 60 * 60 * 60); before(async () => { loadArguments(); - let client = new UAT({ - protocol: 'http', - domain: 'localhost:8080', + let client = new ApiTestingClient({ + protocol: cliArguments.rprotocol, + domain: cliArguments.rdomain, apiPath: '/', }); - const token = await client.getApiToken('default', '1q2w3e'); - console.log(JSON.stringify(token)) - const apiToken = await client.createApiToken(token.access_token, 1, 'testing'+new Date().getTime() ); - console.log(JSON.stringify(apiToken)) + //Using the default user provided by report portal + const token = await client.getApiToken('default', '1q2w3e'); + const apiToken = await client.createApiToken(token.access_token, 1, `testing-${new Date().getTime()}` ); cliArguments.rtoken = apiToken.api_key; testcafeServer = await createTestCafe('localhost', 1337, 1338); }); diff --git a/tests/integration/integration.testcafe.ts b/tests/integration/integration.testcafe.ts index f55e50d..66e0a33 100644 --- a/tests/integration/integration.testcafe.ts +++ b/tests/integration/integration.testcafe.ts @@ -13,8 +13,8 @@ fixture `First fixture` .page('https://google.com') .before(async () => { api = new API({ - protocol: 'http', - domain: 'localhost:8080', + protocol: cliArguments.rprotocol, + domain: cliArguments.rdomain, apiPath: '/api', token: cliArguments.rtoken, })