angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.13k stars 1.24k forks source link

Error with PUT with Sequelize Backend #2180

Open dhaazen opened 8 years ago

dhaazen commented 8 years ago
Item Version
generator-angular-fullstack 4.0.1
Node 4.4.5
npm 3.10.5
Operating System OS X 10
Item Answer
Transpiler Babel
Markup HTML
CSS SCSS
Router ui-router
Client Tests Mocha
DB SQL
Auth N

Hey,

It appears the Mocha PUT tests / Upsert Functionality for the Sequelize backend are broken.

The test expects the object back when according to the Sequelize documentation it only return a true or a false. http://docs.sequelizejs.com/en/latest/api/model/#upsertvalues-options-promisecreated

Although in my case I get undefined... which causes it to not return anything and breaks the backend route entirely. I think it might be because I'm using Postgres... I was able to modify the backend code fine to get around it. but figured I should raise it anyways.

tommyforlini commented 8 years ago

Can you share what modification was made to the backend to solve the issue ?

dhaazen commented 8 years ago

@tommyforlini: Yeah I guess that might be useful. It was pretty hacky essentially just to get the tests to pass which is why I didn't share it to be honest haha. I modified the upsert to pass along the _id in the object:

  // ./server/api/thing/thing.integration.js
  describe('PUT /api/things/:id', function() {
    var updatedThing;

    beforeEach(function(done) {
      request(app)
        .put(`/api/things/${newThing._id}`)
        .send({
          _id: newThing._id,
          name: 'Updated Thing',
          info: 'This is the updated thing!!!'
        })
        .expect(200)
        .expect('Content-Type', /json/)
        .end((err, res) => {
          if(err) {
            return done(err);
          }
          updatedThing = res.body;
          done();
        });
    });

I modified the upsert code to simply upsert the object as is. I removed the where: {_id: req.params.id} part as that appeared to cause an error. The result I get from the upsert is undefined for whatever reason (not true or false like the documentation says) so I just return a blank object and 200 (to satisfy the before each test case in the integration test).

// ./server/api/thing/thing.controller.js
// Upserts the given Thing in the DB at the specified ID
export function upsert(req, res) {

  return Thing.upsert(req.body)
    .then((result) => res.status(200).json({}))
    .catch(handleError(res));
}

Then I removed the following test that checks for returning the "Thing" since that doesn't seem to happen.

    // ./server/api/thing/thing.integration.js
    it('should respond with the original thing', function() {
      expect(updatedThing.name).to.equal('New Thing');
      expect(updatedThing.info).to.equal('This is the brand new thing!!!');
    });

The following GET test which verifies the "Thing" was updated passes so the upsert appears to still work regardless of the peculiar behaviour.

bingomanatee commented 8 years ago

having issues with this too:

US9801A7AB1FD1:skylight2 dedelhart$ gulp test:server [14:02:46] Requiring external module babel-register [14:02:47] Using gulpfile ~/Documents/repos/skylight2/gulpfile.babel.js (node:81059) DeprecationWarning: crypto.createCredentials is deprecated. Use tls.createSecureContext instead. (node:81059) DeprecationWarning: crypto.Credentials is deprecated. Use tls.SecureContext instead. [14:02:47] Starting 'test:server'... [14:02:47] Starting 'env:all'... [14:02:47] Finished 'env:all' after 4.91 ms [14:02:47] Starting 'env:test'... [14:02:47] Finished 'env:test' after 295 μs [14:02:47] Starting 'mocha:unit'...

Thing API Router: ✓ should return an express router instance GET /api/things ✓ should route to thing.controller.index GET /api/things/:id ✓ should route to thing.controller.show Express server listening on 9000, in test mode POST /api/things ✓ should route to thing.controller.create PUT /api/things/:id ✓ should route to thing.controller.upsert PATCH /api/things/:id ✓ should route to thing.controller.patch DELETE /api/things/:id ✓ should route to thing.controller.destroy

7 passing (31ms)

[14:02:48] Finished 'mocha:unit' after 797 ms [14:02:48] Starting 'mocha:integration'...

Thing API: GET /api/things Express server listening on 9000, in test mode GET /api/things 200 17.224 ms - 86 ✓ should respond with JSON array POST /api/things POST /api/things 201 13.723 ms - 68 ✓ should respond with the newly created thing GET /api/things/:id GET /api/things/3 200 3.738 ms - 82 ✓ should respond with the requested thing PUT /api/things/:id 1) "before each" hook for "should respond with the original thing" PATCH /api/things/:id PATCH /api/things/3 200 10.237 ms - 84 ✓ should respond with the patched thing DELETE /api/things/:id DELETE /api/things/3 204 15.377 ms - - ✓ should respond with 204 on successful removal DELETE /api/things/3 404 6.914 ms - - ✓ should respond with 404 when thing does not exist

6 passing (5s) 1 failing

1) Thing API: PUT /api/things/:id "before each" hook for "should respond with the original thing": Error: timeout of 5000ms exceeded. Ensure the done() callback is being called in this test.

<--- Last few GCs --->

59249 ms: Mark-sweep 1256.8 (1434.9) -> 1257.0 (1434.9) MB, 328.0 / 0.0 ms [allocation failure] [scavenge might not succeed]. 59638 ms: Mark-sweep 1257.0 (1434.9) -> 1256.8 (1434.9) MB, 388.6 / 0.0 ms [allocation failure] [scavenge might not succeed]. 59997 ms: Mark-sweep 1256.8 (1434.9) -> 1261.0 (1418.9) MB, 359.3 / 0.0 ms [last resort gc]. 60339 ms: Mark-sweep 1261.0 (1418.9) -> 1264.9 (1418.9) MB, 341.1 / 0.0 ms [last resort gc].

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x2702915cfb51 1: captureStackTrace [native messages.js:~686] [pc=0x15e201286b27](this=0x2702915e6ec1 ,Q=0x15bc459ff3c9 <an Error with map 0x22545a7e9731>,bp=0x2702915b73c1 <JS Function Error %28SharedFunctionInfo 0x270291579b81%29) 2: new constructor(aka Error) [native messages.js:639] [pc=0x15e201250dd1] (this=0x15bc459ff3c9 <an Error with map 0x22545a7e9731>,bn=0x270291504381 <undef...

FATAL ERROR: CALL_AND_RETRYLAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [/usr/local/bin/node] 2: node::FatalException(v8::Isolate, v8::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node] 3: v8::internal::V8::FatalProcessOutOfMemory(char const, bool) [/usr/local/bin/node] 4: v8::internal::Factory::NewFixedArrayWithHoles(int, v8::internal::PretenureFlag) [/usr/local/bin/node] 5: v8::internal::MaybeGrow(v8::internal::Isolate, v8::internal::Handlev8::internal::FixedArray, int, int) [/usr/local/bin/node] 6: v8::internal::Isolate::CaptureSimpleStackTrace(v8::internal::Handlev8::internal::JSReceiver, v8::internal::Handlev8::internal::Object) [/usr/local/bin/node] 7: v8::internal::Isolate::CaptureAndSetSimpleStackTrace(v8::internal::Handlev8::internal::JSReceiver, v8::internal::Handlev8::internal::Object) [/usr/local/bin/node] 8: v8::internal::Runtime_CollectStackTrace(int, v8::internal::Object_, v8::internal::Isolate) [/usr/local/bin/node] 9: 0x15e1ffb092a7 10: 0x15e201286b27 Abort trap: 6 US9801A7AB1FD1:skylight2 dedelhart$

jabas06 commented 7 years ago

I have the same issue about the PUT test, but the biggest issue is the terminal hang that starts when the test results are displayed. The terminal hangs for 30 seconds and ends up crashing with this message:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

This is another issue about the same #2377