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

Create tests for all the API endpoints #43

Open
gigili opened this issue Oct 3, 2020 · 10 comments
Open

Create tests for all the API endpoints #43

gigili opened this issue Oct 3, 2020 · 10 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@gigili
Copy link
Owner

gigili commented Oct 3, 2020

There should be tests created for all the API routes.

Some resources for it:

Testing ExpressJS REST API with Mocha and Chai | Medium
How to Test Nodejs Code and RESTful API | CodeForGeek
Testing NodeJs/Express API with Jest and Supertest | Dev.to
Mocking ExpressJS Request and Response objects | ITNEXT

The projects programming language has changed from typescript to php so these links are no longer useful.
New links:

As always any help and/or feedback is welcomed :)

@gigili gigili added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Oct 3, 2020
@thiagojmlins
Copy link

I'd like to pick this up.

@gigili
Copy link
Owner Author

gigili commented Oct 3, 2020

Hey,

thank you for taking an interest, your help would be much appreciated :)

@thiagojmlins
Copy link

No problem, I hope to be helpful :)

@gigili
Copy link
Owner Author

gigili commented Oct 3, 2020

One thing I'd like to note as I'm not sure if it's obvious from the code itself is that almost all routes expect the guid to be sent and not the numerical id as a parameter for the request.

Some routes such as those for the city and/or country use the numerical ID.

@thiagojmlins
Copy link

thiagojmlins commented Oct 4, 2020

I'm having a problem trying to run migrations. I have setup the MySQL DB, but every time I try to run the db-migrate up, it returns me this error:

`received data: CREATE TABLE `user` (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL ,
    email VARCHAR(100) NOT NULL UNIQUE,
    username VARCHAR(50) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    active ENUM('0','1') NOT NULL DEFAULT '0',
    created_at DATE DEFAULT CURRENT_DATE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `user`
    (name, email, username, password, active)
VALUES
    ('Igor Ilić', '[email protected]', 'gac', 'fac5b2c9d9fe1d6cc567798868a6e02124a50f4d3d4330ea96a95ddb62e9673b', '1');
[ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURRENT_DATE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `user`
    (n' at line 8
    at Query.Sequence._packetToError (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Query.ErrorPacket (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
    at Protocol._parsePacket (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
    --------------------
    at Protocol._enqueue (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Connection.query (/home/thiago/Code/good-food-tracker-api/node_modules/mysql/lib/Connection.js:198:25)
    at /home/thiago/Code/good-food-tracker-api/node_modules/db-migrate-mysql/index.js:450:29
    at Promise._execute (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/promise.js:103:10)
    at Object.runSql (/home/thiago/Code/good-food-tracker-api/node_modules/db-migrate-mysql/index.js:445:12)
    at /home/thiago/Code/good-food-tracker-api/migrations/20200829180451-user.js:32:15
    at tryCatcher (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/thiago/Code/good-food-tracker-api/node_modules/bluebird/js/release/async.js:102:5)`

What am I doing wrong?

@gigili
Copy link
Owner Author

gigili commented Oct 4, 2020

I've noticed that issue my self when using older versions of MariaDB database < 10.4.6.
So if you have a MariaDB version above 10.4.6 it should work. But I'll try and create an sql version of the import file that supports older versions. Because older versions of MariaDB don't support some of the syntax in those queries.

I've successfully imported migrations on versions 10.4.6 and 10.5.5.

@gigili
Copy link
Owner Author

gigili commented Oct 4, 2020

I've merged the new version of migrations into the main branch which should allow you to run all the migrations without any issues. Do let me know if there are any problems with it.

@gigili
Copy link
Owner Author

gigili commented Oct 7, 2020

We you able to run the migrations since the new update?

@thiagojmlins
Copy link

Hi, Igor. Sorry about the delay, these days were exhausting. I've tried to run them after your update, but no luck. Some of the tables didn't update. I'll try another run later today and let you know if I succeed, and if doesn't work, I'll share the output with you.

@gigili
Copy link
Owner Author

gigili commented Oct 7, 2020

Hey, no worries. I think you will need to delete all the tables first and than run the migrations as I didn't create new ones but rather rewrote the old ones. So it needs to be a clean database for it to succeed.

I tested it on 10.4.1 without any issues, so now it should be good.

When you have the time, try and just let me know. If it still throws errors I'll try and update it more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants