Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace server author services specific data generators with fake-data-generator #161

Closed
5 tasks done
sgobotta opened this issue Sep 30, 2019 · 8 comments
Closed
5 tasks done
Assignees
Labels
configuration Project's general configuration enhancement New feature or request good first issue Good for newcomers Hacktoberfest (◡ ‿ ◡ ✿) 2019

Comments

@sgobotta
Copy link
Member

sgobotta commented Sep 30, 2019

In the utils server we are using too many custom functions for the authors fake data. We could replace that using the fake-data-generator as a dev-dependency.

Current models: please respect the current type of each property

author: {
  id: Number, // faker random number
  name: String, // faker random words
  lastname: String, // faker lorem text
  birthdate: ISOString // faker date between
}

Checkpoints:

  • Run the e2e tests, they should pass.
  • Run the unit tests, they should pass.
  • Authors service: Replace ipsum dependency and the custom date format functions with fake-data-generator. Replace the authors array with a new fake-data-generator model of 40 items
  • Rerun e2e tests, they must pass.
  • Rerun unit tests, they must pass.
@sgobotta sgobotta added this to To do in Current Tasks via automation Sep 30, 2019
@sgobotta sgobotta added configuration Project's general configuration good first issue Good for newcomers Hacktoberfest (◡ ‿ ◡ ✿) 2019 labels Sep 30, 2019
@sgobotta sgobotta changed the title Replace server magazine services specific data generators with fake-data-generator Replace server author services specific data generators with fake-data-generator Sep 30, 2019
@jphetphoumy
Copy link

Hi @sgobotta, If nobody is working on this issue, I'll be glad to help !

@sgobotta
Copy link
Member Author

Hi @jphetphoumy, all yours. Let me know if you need any help of any kind. I think the fake-data-generator is ready to accept all the required fields for authors

@sgobotta sgobotta moved this from To do to In progress in Current Tasks Oct 22, 2019
@jphetphoumy
Copy link

Hi !

I tried to do some test with the fake-data-generator but it does not seems to work as expected.

I tried the following code :

// Requires the package
const { generateModel } = require('fake-data-generator')
// Requires a model
const model = require('./models/authors.json')
// Generate the model
const amountArg = 50
const modelArg = 'authors'
const outputType = 'object'
const generatedModel = generateModel({ amountArg, modelArg, outputType })

if authors does not exist in the node_modules/fake-data-generator/dist/models/, I have the following error :

 jeremy@ArchLinux  ~/Document/Code/test-fake-data  node index.js                                                                                              SIGINT(2) ↵  10406  14:21:32
internal/modules/cjs/loader.js:797
    throw err;
    ^

Error: Cannot find module '../models/authors'
Require stack:
- /home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/create-model.js
- /home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/index.js
- /home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/main.js
- /home/jeremy/Document/Code/test-fake-data/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at getModel (/home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/create-model.js:17:19)
    at createSingle (/home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/create-model.js:25:15)
    at /home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/create-model.js:34:12
    at Array.map (<anonymous>)
    at createMany (/home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/create-model.js:33:47)
    at exports.default (/home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/create-model.js:49:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/create-model.js',
    '/home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/lib/index.js',
    '/home/jeremy/Document/Code/test-fake-data/node_modules/fake-data-generator/dist/main.js',
    '/home/jeremy/Document/Code/test-fake-data/index.js'
  ]
}

I looked at the fake-data-generator code and this line seems to be the problem

So here the question,

Do I need to make a pull request to fake-data-generator to add the authors.json model or maybe replace

const modelData = require(`../models/${modelName}`)

by

const modelData = require(path.resolve(`${__dirname}/../models/${modelName}`))

to get the current path ?

@sgobotta
Copy link
Member Author

Oh, it looks kind of horrible. I didn't know the state of the generator when used as an npm dependency.

I think the solution is a bit more comples than looking for a .json in the right place. Anyhow, I'll open an issue in fake-data-generator explaining the situation. Sadly, this task can't be finished until the generator is fixed.

@sgobotta
Copy link
Member Author

Alright, I've just released v0.1.7 for the fake-data-generator. 🎉

@jphetphoumy
Copy link

Cool ! I'll take a look at the issue today !

@jphetphoumy
Copy link

Hi !

I Have looked into the issue, but the faker date.between doesn't seem to work.

I read the fakerjs documentation and It seems that we need to pass some argument to the faker data.between to generate a date :

http://marak.github.io/faker.js/faker.date.html

But I think that fake-data-generator can not handle argument yet :

https://github.com/Cambalab/fake-data-generator/blob/develop/README.md#faker

Also, I didn't see any unit test or e2e test for the authors.js

Would you like me to write them ?

@sgobotta
Copy link
Member Author

sgobotta commented Oct 25, 2019

Hi !

I Have looked into the issue, but the faker date.between doesn't seem to work.

I read the fakerjs documentation and It seems that we need to pass some argument to the faker data.between to generate a date :

http://marak.github.io/faker.js/faker.date.html

But I think that fake-data-generator can not handle argument yet :

https://github.com/Cambalab/fake-data-generator/blob/develop/README.md#faker

Okay, I've just published v0.1.8 for fake-data-generator that provides faker.between support.
I've made a few manual tests and seems to work fine by passing an array of dates as options (see example.json).

Also, I didn't see any unit test or e2e test for the authors.js

Would you like me to write them ?

Just e2e tests :) you can find them here. And you don't even have to implement them, just check they're passing ; )

@sgobotta sgobotta added the enhancement New feature or request label Nov 17, 2019
@sgobotta sgobotta assigned sgobotta and unassigned jphetphoumy Nov 17, 2019
Current Tasks automation moved this from In progress to Done Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Project's general configuration enhancement New feature or request good first issue Good for newcomers Hacktoberfest (◡ ‿ ◡ ✿) 2019
Projects
Current Tasks
  
Done
Development

No branches or pull requests

2 participants