Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
"ignorePatterns": [
"node_modules/",
"database/",
"tests/",
"tmp/",
"scratch/"
"scratch/",
"security",
"hooks/",
"docs/",
"scripts/",
"reports/",
"notes/"
],
"rules": {
"array-bracket-newline": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test": "test"
},
"scripts": {
"eslint": "eslint app --ext .js --format html --output-file ./reports/static/static-analysis.html",
"eslint": "eslint app test --ext .js --format html --output-file ./reports/static/static-analysis.html",
"eslint:fix": "npm run eslint -- --fix",
"eslint:show": "run-script-os",
"eslint:show:linux": "npm run eslint; firefox ./reports/static/static-analysis.html",
Expand Down
1 change: 0 additions & 1 deletion test/api/jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const { expect } = require('chai');

module.exports = async () => {
describe('Get requests', () => {

it('should be protected by a Json Web Token', async () => {
const response = await request(httpServer)
.get('/api/date');
Expand Down
10 changes: 5 additions & 5 deletions test/database/utilities/PGQueryBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
const PGQueryBuilder = require('../../../app/lib/database/utilities/PGQueryBuilder');
const views = require('../../../app/lib/database/views');
const { databaseService } = require('../../../app/lib/database/DatabaseService');
const { assert, expect } = require('chai');

const { expect } = require('chai');
const assert = require('assert');

module.exports = () => {
describe('DatabaseSuite', () => {
Expand Down Expand Up @@ -48,7 +48,7 @@ module.exports = () => {
'beam-match': 'p-p',
};

assert.doesNotThrow( async () => {
await assert.doesNotReject( async () => {
const q = PGQueryBuilder.buildSelect(filteringParams);
await databaseService.pgExec(q);
});
Expand All @@ -68,7 +68,7 @@ module.exports = () => {
'year-between': ['2022,', '2222,2555', ',2055']
};

assert.doesNotThrow( async () => {
await assert.doesNotReject( async () => {
const q = PGQueryBuilder.buildSelect(filteringParams);
await databaseService.pgExec(q);
});
Expand All @@ -90,7 +90,7 @@ module.exports = () => {

};

assert.doesNotThrow( async () => {
await assert.doesNotReject( async () => {
const q = PGQueryBuilder.buildSelect(filteringParams);
await databaseService.pgExec(q);
});
Expand Down
21 changes: 5 additions & 16 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const DatabaseSuite = require('./database');
const ApiSuite = require('./api');
const PublicSuite = require('./public');
const LibSuite = require('./lib');
const assert = require('assert');

const application = require('../app/application.js');

describe('Run Condition Table', () => {
Expand All @@ -28,20 +26,11 @@ describe('Run Condition Table', () => {
after(async () => {
await application.stop(true);
});

describe('App initialization', () => {
it('should initialize the app instance', () => {
assert.doesNotThrow(async () => {
app = new Application({});
await app.stop()
});
});
});


describe('Unit Suite', () => {
describe('Database', DatabaseSuite);
describe('API', ApiSuite),
describe('Public', PublicSuite);
describe('Lib', LibSuite);
describe('Database', DatabaseSuite);
describe('API', ApiSuite),
describe('Public', PublicSuite);
describe('Lib', LibSuite);
});
});
5 changes: 3 additions & 2 deletions test/public/components/itemsCounter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* or submit itself to any jurisdiction.
*/

const req = require('esm')(module)
const req = require('esm')(module);

const itemsCounter = req('../../../app/public/components/table/itemsCounter').default;
const { assert } = require('chai');

Expand All @@ -21,7 +22,7 @@ module.exports = () => {
currentPage: 5,
itemsPerPage: 10,
itemsCount: 57,
}
};
const expectedResult = '41-50 of 57';

it('should count the items as expected', () => {
Expand Down
87 changes: 44 additions & 43 deletions test/public/components/pageTitle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,54 @@
* or submit itself to any jurisdiction.
*/

const req = require('esm')(module)
const req = require('esm')(module);

const { pageTitle } = req('../../../app/public/components/common/pageTitle');
const assert = require('assert');

module.exports = () => {
describe('Page title', () => {
const pageNames = {
periods: 'periods',
dataPasses: 'dataPasses',
mc: 'mc',
anchoredPerMC: 'anchoredPerMC',
anchoragePerDatapass: 'anchoragePerDatapass',
runsPerPeriod: 'runsPerPeriod',
runsPerDataPass: 'runsPerDataPass',
flags: 'flags',
};

it('should return Periods page name' , () => {
assert.equal(pageTitle(pageNames.periods, pageNames), 'Periods');
});

it('should return Data passes page name' , () => {
assert.equal(pageTitle(pageNames.dataPasses, pageNames), 'Data passes per period');
});

it('should return Monte Carlo page name' , () => {
assert.equal(pageTitle(pageNames.mc, pageNames), 'Monte Carlo');
});

it('should return Anchored per MC page name' , () => {
assert.equal(pageTitle(pageNames.anchoredPerMC, pageNames), 'Anchored per MC');
});

it('should return Anchorage per data pass page name' , () => {
assert.equal(pageTitle(pageNames.anchoragePerDatapass, pageNames), 'Anchorage per data pass');
});

it('should return Runs per period page name' , () => {
assert.equal(pageTitle(pageNames.runsPerPeriod, pageNames), 'Runs per period');
});

it('should return Runs per data pass page name' , () => {
assert.equal(pageTitle(pageNames.runsPerDataPass, pageNames), 'Runs per data pass');
});

it('should return Quality flags page name' , () => {
assert.equal(pageTitle(pageNames.flags, pageNames), 'Quality flags');
});
const pageNames = {
periods: 'periods',
dataPasses: 'dataPasses',
mc: 'mc',
anchoredPerMC: 'anchoredPerMC',
anchoragePerDatapass: 'anchoragePerDatapass',
runsPerPeriod: 'runsPerPeriod',
runsPerDataPass: 'runsPerDataPass',
flags: 'flags',
};

it('should return Periods page name', () => {
assert.equal(pageTitle(pageNames.periods, pageNames), 'Periods');
});

it('should return Data passes page name', () => {
assert.equal(pageTitle(pageNames.dataPasses, pageNames), 'Data passes per period');
});

it('should return Monte Carlo page name', () => {
assert.equal(pageTitle(pageNames.mc, pageNames), 'Monte Carlo');
});

it('should return Anchored per MC page name', () => {
assert.equal(pageTitle(pageNames.anchoredPerMC, pageNames), 'Anchored per MC');
});

it('should return Anchorage per data pass page name', () => {
assert.equal(pageTitle(pageNames.anchoragePerDatapass, pageNames), 'Anchorage per data pass');
});

it('should return Runs per period page name', () => {
assert.equal(pageTitle(pageNames.runsPerPeriod, pageNames), 'Runs per period');
});

it('should return Runs per data pass page name', () => {
assert.equal(pageTitle(pageNames.runsPerDataPass, pageNames), 'Runs per data pass');
});

it('should return Quality flags page name', () => {
assert.equal(pageTitle(pageNames.flags, pageNames), 'Quality flags');
});
});
};
7 changes: 4 additions & 3 deletions test/public/periods/overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const {
defaultBefore,
defaultAfter,
goToPage,
expectInnerText
expectInnerText,
} = require('../defaults');

const { expect } = chai;

module.exports = () => {
Expand All @@ -40,10 +41,10 @@ module.exports = () => {
describe('Periods overview', () => {
it('loads the page successfully', async () => {
const response = await goToPage(page, 'periods');

// We expect the page to return the correct status code, making sure the server is running properly
expect(response.status()).to.equal(200);

// We expect the page to return the correct title, making sure there isn't another server running on this port
const title = await page.title();
expect(title).to.equal('RCT prototype');
Expand Down
23 changes: 13 additions & 10 deletions test/public/utils/dataExport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* or submit itself to any jurisdiction.
*/

const req = require('esm')(module)
const req = require('esm')(module);

const { replacer, prepareCSVContent } = req('../../../app/public/utils/dataExport/export');
const { assert } = require('chai');

module.exports = () => {
describe('CSV Export', () => {

describe('Replacer', () => {
const sampleObject = {
a: 1,
Expand All @@ -37,31 +37,34 @@ module.exports = () => {
};

it('should replace null values with empty string', () => {
assert.deepEqual(Object.keys(sampleObject).reduce((acc, key) => ({...acc, [key]: replacer(key, sampleObject[key])}), {}), expectedResult);
assert.deepEqual(
Object.keys(sampleObject).reduce((acc, key) => ({ ...acc, [key]: replacer(key, sampleObject[key]) }), {}),
expectedResult,
);
});
});

describe('Check data preparation', () => {
const rawData = [
{
name: "LHC23zt",
name: 'LHC23zt',
year: 2023,
beamType: "p-p",
beamType: 'p-p',
avgEnergy: 13595,
distinctEnergies: [6797.04, 6797.52, 6797.64, 6798],
},
{
name: "LHC23zs",
name: 'LHC23zs',
year: 2023,
beamType: "p-p",
beamType: 'p-p',
avgEnergy: 13596,
distinctEnergies: [6797.4, 6797.52, 6797.64, 6797.76, 6797.88, 6798, 6798.24, 6799.2],
}
},
];

const preparedData = 'name,year,beamType,avgEnergy,distinctEnergies\r\n' +
`"LHC23zt",2023,"p-p",13595,[6797.04,6797.52,6797.64,6798]\r\n` +
`"LHC23zs",2023,"p-p",13596,[6797.4,6797.52,6797.64,6797.76,6797.88,6798,6798.24,6799.2]`;
'"LHC23zt",2023,"p-p",13595,[6797.04,6797.52,6797.64,6798]\r\n' +
'"LHC23zs",2023,"p-p",13596,[6797.4,6797.52,6797.64,6797.76,6797.88,6798,6798.24,6799.2]';

it('should prepare CSV data content', () => {
assert.equal(prepareCSVContent(rawData), preparedData);
Expand Down
Loading