Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
danitseitlin committed Sep 28, 2024
1 parent 310f471 commit 44b892a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 53 deletions.
12 changes: 0 additions & 12 deletions scripts/healthcheck.bash
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
34 changes: 7 additions & 27 deletions src/uat.js → src/api-testing-client.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -172,4 +152,4 @@ class UAT {
}
}

module.exports = UAT;
module.exports = ApiTestingClient;
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
15 changes: 7 additions & 8 deletions tests/integration/integration.executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/integration.testcafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down

0 comments on commit 44b892a

Please sign in to comment.