Skip to content

Commit

Permalink
Now the test establish the connection to the MongoMemoryServer(???)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelMH1 committed May 2, 2024
1 parent dc18d6d commit 2dccb98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ db.once('open', () => console.log("Connected to MongoDB: %s", mongoUri));

function close() {
mongoose.connection.close();
mongoose.disconnect();
}

const templates = [
Expand Down Expand Up @@ -92,4 +91,4 @@ async function startJob(minutes = 30, startQuery = 0) {

startJob();

module.exports = { startJob, extractData, close };
module.exports = { startJob, close };
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { MongoMemoryServer } = require('mongodb-memory-server');
const cron = require('node-cron');
let startJob, extractData, close;
let startJob, close;

const modelUri = process.env.DATAMODELS_URI || '../questiondata-model';
const { Pais } = require(modelUri);

jest.mock('node-cron', () => {
return {
Expand All @@ -16,7 +19,14 @@ beforeAll(async () => {
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;

({ startJob, extractData, close } = await require('./wikidataextractor-service'));
({ startJob, close } = require('./wikidataextractor-service'));

const newPais1 = new Pais({
pais: 'Japan',
capital: 'Tokyo',
continente: 'Asia'
});
await newPais1.save();
});

afterAll(async () => {
Expand All @@ -36,8 +46,8 @@ describe('Test the Wikidata Conexion', () => {
json: () => Promise.resolve({
results: {
bindings: [
{ countryLabel: 'Spain', capitalLabel: 'Madrid' },
{ countryLabel: 'France', capitalLabel: 'Paris' }
{ countryLabel: { value: 'Spain' }, capitalLabel: { value: 'Madrid' } },
{ countryLabel: { value: 'France' }, capitalLabel: { value: 'Paris' } }
]
}
}),
Expand All @@ -57,8 +67,8 @@ describe('Test the Wikidata Conexion', () => {
json: () => Promise.resolve({
results: {
bindings: [
{ countryLabel: 'Spain', capitalLabel: 'Madrid' },
{ countryLabel: 'France', capitalLabel: 'Paris' }
{ countryLabel: { value: 'Spain' }, capitalLabel: { value: 'Madrid' } },
{ countryLabel: { value: 'France' }, capitalLabel: { value: 'Paris' } }
]
}
}),
Expand All @@ -80,8 +90,8 @@ describe('Test the different Wikidata Queries', () => {
json: () => Promise.resolve({
results: {
bindings: [
{ countryLabel: 'Spain', capitalLabel: 'Madrid' },
{ countryLabel: 'France', capitalLabel: 'Paris' }
{ countryLabel: { value: 'Spain' }, capitalLabel: { value: 'Madrid' } },
{ countryLabel: { value: 'France' }, capitalLabel: { value: 'Paris' } }
]
}
}),
Expand Down

0 comments on commit 2dccb98

Please sign in to comment.