idurar / idurar-erp-crm

Open Source Headless ERP CRM E-Commerce Accounting Software | Node Js React
https://cloud.idurarapp.com/
Other
6.17k stars 1.84k forks source link

[feat] setup jest and supertest for backend #346

Open MattGould1 opened 1 year ago

MattGould1 commented 1 year ago

Hey,

I'd like to get your opinions on introducing Jest for unit testing on the backend and then secondary to that, creating a way to create test data for the unit tests.

I would propose changing a few structures first, for our controllers we have the file paths of

Controllers

controllers/erpControllers/adminController.js

I would propose to change this to

controllers/erpControllers/adminController/index.js
controllers/erpControllers/adminController/index.test.js

This could then be extended later to include index.test.integration.ts for integration tests.

Models

Currently we have our model files like so

models/erpModels/Admin.js

I'd like to change this so that a model can also have a generator to create the test data for that model.

models/erpModels/Admin/index.js
models/erpModels/Admin/generate.js

Generate.js

The generate.js would look something like:

const faker = require('@faker-js/faker');
const Admin = mongoose.model('Admin');

const generateAdmin = (input) => {
  return new Admin({
    ...input,
    surname: faker.name.lastName(),
    // More fields here
  })
}

export default generateAdmin

Test Data

We would want a way to create test data on the fly for whatever purpose it is required and be able to relate the data. I'd propose something like below:

    await resetDatabase({
      testData: {
        Admin: [{}],
        Employee: [{}, {}, {}],
        Expense: [{ expenseCategory: 0 }],
        ExpenseCategory: [{}]
      },
    });

This would create:

1 Admin, 3 Employee's, 1 Expensive which has an Expense cateogry and 1 Expense Category that belongs to an Expense

salahlalami commented 1 year ago

Hi @MattGould1 , you are welcome to contribute setup jest and supertest for backend

Zewenaco commented 1 year ago

Hello! I'd like to contribute to this project. Is anyone there working in this proposal? Maybe I could be help or if anyone is working on it I can take it and try 👍

Vishrut19 commented 1 year ago

Can I take up this issue?

parteekcoder commented 1 year ago

@Vishrut19 @Zewenaco you are welcomed to contribute on this issue

Tint-d commented 8 months ago

hey Can I get ER Diagram

drethedevjs commented 6 months ago

@parteekcoder @salahlalami Has anyone started on this issue?

irfanseikh2011 commented 6 months ago

I've created a unit test suite for the controllers and would welcome any feedback or suggestions you might have.

1008 @drethedevjs @salahlalami

MSNoorul commented 2 months ago

Can I create tests for both frontend and backend? Can I add test cases? Is this project still active?