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 06b9359 commit 58c2ea3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/api-testing-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ class ApiTestingClient {

/**
* We create an API key to use it later on in our tests.
* @param {*} token
* @param {*} userId
* @param {*} name
* @returns
* @param {*} token The UAT token to gain permissions to create an API key
* @param {*} userId The id of the user
* @param {*} name The name of the token
* @returns The api key object
*/
async createApiToken(token, userId, name) {
async createApiKey(token, userId, name) {
try {
this.setApiToken(token);
const response = await this.client.post(`api/users/${userId}/api-keys`, {name: name});
Expand Down
41 changes: 22 additions & 19 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class API {
}
}

/**
* Retrieves a list of the project latest launches
* @param {*} projectName The project name
* @returns A list of the latest project launches
*/
async getLaunches(projectName) {
try {
const response = await this.client.get(`/v1/${projectName}/launch/latest`);
Expand All @@ -182,7 +187,13 @@ class API {
}
}

async getItems(projectName, launchId) {
/**
* Retrieves a list of test items
* @param {*} projectName The project name
* @param {*} launchId The launch id
* @returns A list of test items that are part of a project and a launch
*/
async getTestItems(projectName, launchId) {
try {
const response = await this.client.get(`/v1/${projectName}/item?filter.eq.launchId=${launchId}&isLatest=false&launchesLimit=0`);
return this.handleResponse(response).content;
Expand All @@ -192,10 +203,17 @@ class API {
}
}

async getItemLogs(projectName, itemId, logLevel='info') {
/**
* Retrieves a list of logs under a test item
* @param {*} projectName The project name
* @param {*} itemId The test item id
* @param {*} logLevel The log level. Default: info
* @returns A list of test item logs
*/
async getTestItemLogs(projectName, testItemId, logLevel='info') {
try {
const response = await this.client.post(`/v1/${projectName}/log/under`, {
itemIds: [itemId],
itemIds: [testItemId],
logLevel: logLevel
});
return this.handleResponse(response)[itemId];
Expand All @@ -204,24 +222,9 @@ class API {
return this.handleError(error);
}
}

/**
* Retrieving all logs in a project
* @param {*} projectName The name of the project
* @returns A list of logs
*/
async getLogs(projectName) {
try {
const response = await this.client.get(`/v1/${projectName}/log`);
return this.handleResponse(response);
}
catch (error) {
return this.handleError(error);
}
}

/**
* Checking if item is a valid JSON
* Checking if item is a valid JSON by attempting to parse it
* @param {*} json The string of the JSON
*/
isJSON (json) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/integration.executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Performing Integration testing', async function() {

//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()}` );
const apiToken = await client.createApiKey(token.access_token, 1, `testing-${new Date().getTime()}` );
cliArguments.rtoken = apiToken.api_key;
testcafeServer = await createTestCafe('localhost', 1337, 1338);
});
Expand Down
11 changes: 2 additions & 9 deletions tests/integration/integration.testcafe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { t } from 'testcafe';
import { cliArguments } from 'cli-argument-parser';
declare global {
interface TestController {
testRun: {
name: string;
};
}
}
const API = require('../../src/api.js');
let api: typeof API;
fixture `First fixture`
Expand Down Expand Up @@ -51,10 +44,10 @@ async function logAndVerify(testName: string, logMsg: any) {
let launches = await api.getLaunches(cliArguments.rproject);
launches = launches.filter(l => l.name === cliArguments.rlaunch)
const launchId = launches[0].id;
const items = await api.getItems(cliArguments.rproject, launchId, testName)
const items = await api.getTestItems(cliArguments.rproject, launchId, testName)

const item = items.find(item => item.name === testName && item.type === 'TEST')
const logs = await api.getItemLogs(cliArguments.rproject, item.id)
const logs = await api.getTestItemLogs(cliArguments.rproject, item.id)

const filteredLogs = logs.filter(l => l.message === message);

Expand Down

0 comments on commit 58c2ea3

Please sign in to comment.