Skip to content

Commit

Permalink
wip reorganize test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecoin committed Nov 22, 2024
1 parent b1b2290 commit 7ef52a9
Showing 1 changed file with 139 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,142 +14,30 @@ const {

describe('Acceptance | Controller | scenario-simulator-controller', function () {
let server;
let adminAuthorization;
let validPayload;

beforeEach(async function () {
const { id: adminId } = databaseBuilder.factory.buildUser.withRole({
role: SUPER_ADMIN,
});

databaseBuilder.factory.buildFlashAlgorithmConfiguration({
maximumAssessmentLength: 2,
createdAt: new Date('2022-02-01'),
});

adminAuthorization = generateValidRequestAuthorizationHeader(adminId);
await databaseBuilder.commit();

validPayload = {
capacity: 4.5,
};

const learningContent = {
competences: [
{
id: 'rec1',
name_i18n: {
fr: 'comp1Fr',
en: 'comp1En',
},
index: '1.1',
color: 'rec1Color',
skillIds: ['skill1', 'skill2'],
},
{
id: 'rec2',
name_i18n: {
fr: 'comp2Fr',
en: 'comp2En',
},
index: '2.1',
color: 'rec2Color',
skillIds: ['skill3', 'skill4', 'skill5'],
},
],
tubes: [
{ id: 'recTube1', competenceId: 'rec1' },
{ id: 'recTube2', competenceId: 'rec2' },
],
skills: [
// tube 1
{ id: 'skill1', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 1, pixValue: 1 },
{ id: 'skill2', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 3, pixValue: 10 },
// tube 2
{ id: 'skill3', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 2, pixValue: 100 },
{ id: 'skill4', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 3, pixValue: 1000 },
{ id: 'skill5', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 5, pixValue: 10000 },
{ id: 'skill6', status: 'périmé', tubeId: 'recTube2', competenceId: 'rec2', level: 6, pixValue: 100000 },
],
challenges: [
{
id: 'challenge1',
skillId: 'skill1',
status: 'validé',
alpha: 0.16,
delta: -2,
locales: ['fr-fr'],
successProbabilityThreshold: 0.3,
},
{
id: 'challenge2',
skillId: 'skill2',
status: 'validé',
alpha: 3,
delta: 6,
locales: ['fr-fr'],
successProbabilityThreshold: 0.4,
},
{
id: 'challenge3',
skillId: 'skill3',
status: 'validé',
alpha: 1.587,
delta: 8.5,
locales: ['fr-fr'],
successProbabilityThreshold: 0.5,
},
{
id: 'challenge4',
skillId: 'skill4',
status: 'validé',
alpha: 2.86789,
delta: 0.145,
locales: ['fr-fr'],
successProbabilityThreshold: 0.6,
},
{
id: 'challenge5',
skillId: 'skill5',
status: 'validé',
alpha: 3,
delta: 1,
locales: ['fr-fr'],
successProbabilityThreshold: 0.7,
},
{
id: 'challenge6',
skillId: 'skill5',
status: 'validé',
alpha: 1.7,
delta: -1,
locales: ['fr-fr'],
successProbabilityThreshold: 0.8,
},
],
};

mockLearningContent(learningContent);

server = await createServer();
});
let options;

describe('#simulateFlashAssessmentScenario', function () {
let options;

beforeEach(async function () {
options = {
method: 'POST',
url: `/api/scenario-simulator`,
payload: {},
headers: {},
};
server = await createServer();
});

it('should return a report with the same number of simulation scenario reports as the number of challenges in the configuration', async function () {
// given
options.headers.authorization = adminAuthorization;
options.payload = validPayload;
const adminAuthorization = _buildSuperAdminUser();
_buildLearningContent();
await _buildAlgorithmConfiguration();

const options = {
method: 'POST',
url: `/api/scenario-simulator`,
payload: {
capacity: 4.5,
},
headers: {
authorization: adminAuthorization,
},
};

// when
const response = await server.inject(options);
Expand All @@ -170,6 +58,10 @@ describe('Acceptance | Controller | scenario-simulator-controller', function ()
describe('when there is no connected user', function () {
it('should return status code 401', async function () {
// given
databaseBuilder.factory.buildUser.withRole({
role: SUPER_ADMIN,
});
await databaseBuilder.commit();
options.headers.authorization = undefined;

// when
Expand Down Expand Up @@ -199,7 +91,9 @@ describe('Acceptance | Controller | scenario-simulator-controller', function ()
describe('when request payload is invalid', function () {
it('should return status code 400', async function () {
// given
options.headers.authorization = adminAuthorization;
const { id: userId } = databaseBuilder.factory.buildUser();
await databaseBuilder.commit();
options.headers.authorization = generateValidRequestAuthorizationHeader(userId);
options.payload = {
wrongField: [],
};
Expand All @@ -213,3 +107,119 @@ describe('Acceptance | Controller | scenario-simulator-controller', function ()
});
});
});

function _buildSuperAdminUser() {
const userId = databaseBuilder.factory.buildUser.withRole({
role: SUPER_ADMIN,
}).id;

return generateValidRequestAuthorizationHeader(userId);
}

async function _buildAlgorithmConfiguration() {
databaseBuilder.factory.buildFlashAlgorithmConfiguration({
maximumAssessmentLength: 2,
createdAt: new Date('2022-02-01'),
});

await databaseBuilder.commit();
}

function _buildLearningContent() {
const learningContent = {
competences: [
{
id: 'rec1',
name_i18n: {
fr: 'comp1Fr',
en: 'comp1En',
},
index: '1.1',
color: 'rec1Color',
skillIds: ['skill1', 'skill2'],
},
{
id: 'rec2',
name_i18n: {
fr: 'comp2Fr',
en: 'comp2En',
},
index: '2.1',
color: 'rec2Color',
skillIds: ['skill3', 'skill4', 'skill5'],
},
],
tubes: [
{ id: 'recTube1', competenceId: 'rec1' },
{ id: 'recTube2', competenceId: 'rec2' },
],
skills: [
// tube 1
{ id: 'skill1', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 1, pixValue: 1 },
{ id: 'skill2', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 3, pixValue: 10 },
// tube 2
{ id: 'skill3', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 2, pixValue: 100 },
{ id: 'skill4', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 3, pixValue: 1000 },
{ id: 'skill5', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 5, pixValue: 10000 },
{ id: 'skill6', status: 'périmé', tubeId: 'recTube2', competenceId: 'rec2', level: 6, pixValue: 100000 },
],
challenges: [
{
id: 'challenge1',
skillId: 'skill1',
status: 'validé',
alpha: 0.16,
delta: -2,
locales: ['fr-fr'],
successProbabilityThreshold: 0.3,
},
{
id: 'challenge2',
skillId: 'skill2',
status: 'validé',
alpha: 3,
delta: 6,
locales: ['fr-fr'],
successProbabilityThreshold: 0.4,
},
{
id: 'challenge3',
skillId: 'skill3',
status: 'validé',
alpha: 1.587,
delta: 8.5,
locales: ['fr-fr'],
successProbabilityThreshold: 0.5,
},
{
id: 'challenge4',
skillId: 'skill4',
status: 'validé',
alpha: 2.86789,
delta: 0.145,
locales: ['fr-fr'],
successProbabilityThreshold: 0.6,
},
{
id: 'challenge5',
skillId: 'skill5',
status: 'validé',
alpha: 3,
delta: 1,
locales: ['fr-fr'],
successProbabilityThreshold: 0.7,
},
{
id: 'challenge6',
skillId: 'skill5',
status: 'validé',
alpha: 1.7,
delta: -1,
locales: ['fr-fr'],
successProbabilityThreshold: 0.8,
},
],
};

mockLearningContent(learningContent);
}

0 comments on commit 7ef52a9

Please sign in to comment.