Skip to content

Commit

Permalink
feat(api): add thematics, frameworks and missions table
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Bergoens committed Dec 30, 2024
1 parent 439441a commit e1625fe
Show file tree
Hide file tree
Showing 4 changed files with 564 additions and 474 deletions.
32 changes: 32 additions & 0 deletions src/steps/learning-content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import * as lcmsClient from './lcms-client.js';
import * as databaseHelper from '../../database-helper.js';

const tables = [{
name: 'frameworks',
fields: [
{ name: 'name', type: 'text' },
],
indexes: [],
}, {
name: 'areas',
fields: [
{ name: 'name', type: 'text' },
Expand All @@ -27,6 +33,15 @@ const tables = [{
{ name: 'areaId', type: 'text', isArray: false },
],
indexes: ['areaId'],
}, {
name: 'thematics',
fields: [
{ name: 'name', type: 'text' },
{ name: 'index', type: 'smallint' },
{ name: 'competenceId', type: 'text', isArray: false },
{ name: 'tubeIds', type: 'text', isArray: true },
],
indexes: [],
}, {
name: 'tubes',
fields: [
Expand Down Expand Up @@ -117,6 +132,23 @@ const tables = [{
{ name: 'locale', type: 'text' },
],
indexes: ['title'],
}, {
name: 'missions',
fields: [
{ name: 'name', type: 'text', extractor: (record) => record.name_i18n.fr },
{ name: 'cardImageUrl', type: 'text' },
{ name: 'competenceId', type: 'text', isArray: false },
{ name: 'thematicIds', type: 'text', isArray: true },
{ name: 'learningObjectives', type: 'text', extractor: (record) => record.learningObjectives_i18n.fr },
{ name: 'validatedObjectives', type: 'text', extractor: (record) => record.validatedObjectives_i18n.fr },
{ name: 'introductionMediaUrl', type: 'text' },
{ name: 'introductionMediaType', type: 'text' },
{ name: 'introductionMediaAlt', type: 'text', extractor: (record) => record.introductionMediaAlt_i18n.fr },
{ name: 'status', type: 'text' },
{ name: 'documentationUrl', type: 'text' },
{ name: 'content', type: 'jsonb', extractor: (record) => JSON.stringify(record.content) },
],
indexes: [],
}];

async function run(configuration, dependencies = { databaseHelper: databaseHelper, lcmsClient: lcmsClient }) {
Expand Down
18 changes: 18 additions & 0 deletions test/acceptance/full-dump-replication-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ describe('Acceptance | fullReplicationAndEnrichment', function() {
await runLearningContent(configuration, { lcmsClient: lcmClientStub, databaseHelper: databaseHelper });
});

it('should import frameworks ', async function() {
// then
const result = await getCountFromTable({ targetDatabase, tableName: 'frameworks' });
expect(result).to.equal(fullLearningContent.frameworks.length);
});

it('should import areas ', async function() {
// then
const result = await getCountFromTable({ targetDatabase, tableName: 'areas' });
Expand All @@ -129,6 +135,12 @@ describe('Acceptance | fullReplicationAndEnrichment', function() {
expect(result).to.equal(fullLearningContent.competences.length);
});

it('should import thematics ', async function() {
// then
const result = await getCountFromTable({ targetDatabase, tableName: 'thematics' });
expect(result).to.equal(fullLearningContent.thematics.length);
});

it('should import tubes ', async function() {
// then
const result = await getCountFromTable({ targetDatabase, tableName: 'tubes' });
Expand All @@ -152,6 +164,12 @@ describe('Acceptance | fullReplicationAndEnrichment', function() {
const result = await getCountFromTable({ targetDatabase, tableName: 'tutorials' });
expect(result).to.equal(fullLearningContent.tutorials.length);
});

it('should import missions ', async function() {
// then
const result = await getCountFromTable({ targetDatabase, tableName: 'missions' });
expect(result).to.equal(fullLearningContent.missions.length);
});
});

describe('should enrich imported data', function() {
Expand Down
9 changes: 6 additions & 3 deletions test/unit/steps/learning-content/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,26 @@ describe('Unit | Steps | learning-content | index.js', function() {
});

it('should drop existing learning-content tables', async function() {
expect(databaseHelper.dropTable.callCount).to.equal(8);
expect(databaseHelper.dropTable.callCount).to.equal(11);
expect(databaseHelper.dropTable).to.have.been.calledWith('frameworks');
expect(databaseHelper.dropTable).to.have.been.calledWith('areas');
expect(databaseHelper.dropTable).to.have.been.calledWith('attachments');
expect(databaseHelper.dropTable).to.have.been.calledWith('competences');
expect(databaseHelper.dropTable).to.have.been.calledWith('thematics');
expect(databaseHelper.dropTable).to.have.been.calledWith('tubes');
expect(databaseHelper.dropTable).to.have.been.calledWith('skills');
expect(databaseHelper.dropTable).to.have.been.calledWith('challenges');
expect(databaseHelper.dropTable).to.have.been.calledWith('courses');
expect(databaseHelper.dropTable).to.have.been.calledWith('tutorials');
expect(databaseHelper.dropTable).to.have.been.calledWith('missions');
});

it('should create learning-content tables', async function() {
expect(databaseHelper.createTable.callCount).to.equal(8);
expect(databaseHelper.createTable.callCount).to.equal(11);
});

it('should insert learning-content data', async function() {
expect(databaseHelper.saveLearningContent.callCount).to.equal(8);
expect(databaseHelper.saveLearningContent.callCount).to.equal(11);
});
});
});
Loading

0 comments on commit e1625fe

Please sign in to comment.