Skip to content

Commit

Permalink
PARTIAL Add VoiceOver Bot
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed May 20, 2024
1 parent a062f63 commit 9748e5f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 19 deletions.
16 changes: 13 additions & 3 deletions client/utils/automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ export const isSupportedByResponseCollector = ctx => {
return false;
}
return (
ctx.at.name === 'NVDA' &&
(ctx.browser.name === 'Chrome' || ctx.browser.name === 'Firefox')
(ctx.at.name === 'NVDA' &&
(ctx.browser.name === 'Chrome' ||
ctx.browser.name === 'Firefox')) ||
(ctx.at.name === 'VoiceOver' && ctx.browser.name === 'Safari')
);
};

// TODO: Stub, support for more bot users should be added
/**
* @param {} [at]
* @param {} [browser]
*
* @returns {string|undefined}
*/
export const getBotUsernameFromAtBrowser = (at, browser) => {
if (at?.name === 'NVDA' && browser?.name === 'Chrome') {
return 'NVDA Bot';
}
if (at?.name === 'VoiceOver' && browser?.name === 'Safari') {
return 'Safari Bot';
}
};
13 changes: 10 additions & 3 deletions server/models/services/CollectionJobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
createTestPlanRun,
removeTestPlanRunById
} = require('./TestPlanRunService');
const responseCollectionUser = require('../../util/responseCollectionUser');
const responseCollectionUserIDs = require('../../util/responseCollectionUserIDs');
const { getTestPlanReportById } = require('./TestPlanReportService');
const { HttpQueryError } = require('apollo-server-core');
const { default: axios } = require('axios');
Expand Down Expand Up @@ -188,7 +188,11 @@ const collectionJobTestStatusAssociation =

/**
* @param {object} options
* @param {object} options.values - CollectionJob to be created
* @param {object} options.values
* @param {string} options.values.status - Status of CollectionJob to be created
* @param {number} options.values.testerUserId - ID of the Tester to which the CollectionJob should be assigned
* @param {object} options.values.testPlanReportId - ID of the TestPlan with which the CollectionJob should be associated
* @param {object} [options.values.testPlanRun] - TestPlan with wich the CollectionJob should be associated (if not provided, a new TestPlan will be created)
* @param {string[]} options.collectionJobAttributes - CollectionJob attributes to be returned in the result
* @param {string[]} options.collectionJobTestStatusAttributes - CollectionJobTestStatus attributes to be returned in the result
* @param {string[]} options.testPlanReportAttributes - TestPlanReport attributes to be returned in the result
Expand All @@ -203,6 +207,7 @@ const collectionJobTestStatusAssociation =
const createCollectionJob = async ({
values: {
status = COLLECTION_JOB_STATUS.QUEUED,
testerUserId,
testPlanRun,
testPlanReportId
},
Expand All @@ -220,7 +225,7 @@ const createCollectionJob = async ({
if (!testPlanRun) {
testPlanRun = await createTestPlanRun({
values: {
testerUserId: responseCollectionUser.id,
testerUserId,
testPlanReportId: testPlanReportId,
isAutomated: true
},
Expand Down Expand Up @@ -538,6 +543,7 @@ const scheduleCollectionJob = async (
const tests = await runnableTestsResolver(report, null, context);
const { directory } = report.testPlanVersion.testPlan;
const { gitSha } = report.testPlanVersion;
const testerUserId = responseCollectionUserIDs['NVDA Bot'];

if (!tests || tests.length === 0) {
throw new Error(
Expand All @@ -560,6 +566,7 @@ const scheduleCollectionJob = async (
const job = await createCollectionJob({
values: {
status: COLLECTION_JOB_STATUS.QUEUED,
testerUserId,
testPlanReportId
},
transaction
Expand Down
5 changes: 5 additions & 0 deletions server/models/services/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ const getUsers = async ({
});
};

/**
*/
const getBotByAt = async ({ transaction }) => {};

Check failure on line 153 in server/models/services/UserService.js

View workflow job for this annotation

GitHub Actions / Using NodeJS and Postgres 12

'transaction' is defined but never used

/**
* @param {object} options
* @param {string|any} options.search - use this to combine with {@param filter} to be passed to Sequelize's where clause
Expand Down Expand Up @@ -464,6 +468,7 @@ module.exports = {
getUserById,
getUserByUsername,
getUsers,
getBotByAt,
getUserRoles,
getUserAts,
createUser,
Expand Down
10 changes: 5 additions & 5 deletions server/seeders/20231218191524-addNVDABot.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

const responseCollectionUser = require('../util/responseCollectionUser');
const responseCollectionUserIDs = require('../util/responseCollectionUserIDs');

module.exports = {
async up(queryInterface) {
const user = await queryInterface.bulkInsert(
'User',
[
{
id: responseCollectionUser.id, // Specified ID for NVDA Bot
username: responseCollectionUser.username,
isBot: responseCollectionUser.isBot,
id: responseCollectionUserIDs['NVDA Bot'],
username: 'NVDA Bot',
isBot: true,
createdAt: new Date(),
updatedAt: new Date()
}
Expand All @@ -28,7 +28,7 @@ module.exports = {

async down(queryInterface) {
await queryInterface.bulkDelete('User', {
id: responseCollectionUser.id
id: responseCollectionUserIDs['NVDA Bot']
});
}
};
34 changes: 34 additions & 0 deletions server/seeders/20240516191524-addVoiceOverBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const responseCollectionUserIDs = require('../util/responseCollectionUserIDs');

module.exports = {
async up(queryInterface) {
const user = await queryInterface.bulkInsert(
'User',
[
{
id: responseCollectionUserIDs['VoiceOver Bot'],
username: 'VoiceOver Bot',
isBot: true,
createdAt: new Date(),
updatedAt: new Date()
}
],
{ returning: true }
);

await queryInterface.bulkInsert('UserRoles', [
{
userId: user[0].id,
roleName: 'TESTER'
}
]);
},

async down(queryInterface) {
await queryInterface.bulkDelete('User', {
id: responseCollectionUserIDs['VoiceOver Bot']
});
}
};
4 changes: 4 additions & 0 deletions server/tests/models/services/UserService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,8 @@ describe('UserModel Data Checks', () => {
expect(user1Ats[0].userId).toBe(_userId);
expect(user1Ats[0].atId).toBeTruthy();
});

describe('getBotByAt', () => {
it('should do things', async () => {});

Check warning on line 339 in server/tests/models/services/UserService.test.js

View workflow job for this annotation

GitHub Actions / Using NodeJS and Postgres 12

Test has no assertions
});
});
8 changes: 0 additions & 8 deletions server/util/responseCollectionUser.js

This file was deleted.

4 changes: 4 additions & 0 deletions server/util/responseCollectionUserIDs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'NVDA Bot': 9999,
'VoiceOver Bot': 9998
};

0 comments on commit 9748e5f

Please sign in to comment.