meanjs / generator-meanjs

MEAN.JS Official Yeoman Generator
http://meanjs.org/
473 stars 177 forks source link

yo meanjs:crud-module <module-name> - create fails #258

Open dhagan opened 7 years ago

dhagan commented 7 years ago

After generating am module the call to $resource.save() fails - the path to the api - http://localhost:3000/api/module-name/create/module-name POST fails with 404 for the obvious reason, the trailing /module-name

The workaround to this is to clone the articles.client.service.js code -

` angular.extend(Article.prototype, { createOrUpdate: function () { var article = this; return createOrUpdate(article); } });

return Article;

. . . `

into your module.

Can someone confirm the module-name.client.controller.js :: vm.module-name reference to the service is being corrupted?

Thanks to the team who is maintaining the mean.js stack - I rely on it heavily.

estock commented 7 years ago

Having the same issue

nithin-ideas2it commented 7 years ago

+1, Any hot fix at least?

Vikky commented 7 years ago

Having the same issue running with yo meanjs --version = 1.8.5

nithin-ideas2it commented 7 years ago

Hi,

I am not 100% sure about the issue since the post request URL is appending the module name with API request.

Ex: if module name is 'note'

Expected: method: post URL: localhost:3000/api/notes

actual: url: localhost:3000/notes/api/notes - not found - issue

in file: modules/core/client/app/init.js

Try this may help. If not then it is a different issue.

Vikky commented 7 years ago

@nithin-ideas2it that worked,thanks a lot.!

cliffeby commented 7 years ago

Seems to work, but I'm now getting not-found#! instead of api in the browser url.

ghost commented 7 years ago

I am getting a similar error when generating crud modules:

[23:00:48] Starting 'mocha'... unable to find logging file configuration Article Admin CRUD tests ✓ should be able to save an article if logged in (197ms) ✓ should be able to update an article if signed in (84ms) ✓ should not be able to save an article if no title is provided (72ms) ✓ should be able to delete an article if signed in (92ms) ✓ should be able to get a single article if signed in and verify the custom "isCurrentUserOwner" field is set to "true" (68ms) Article Model Unit Tests: Method Save ✓ should be able to save without problems ✓ should be able to show an error when try to save without title Article CRUD tests ✓ should not be able to save an article if logged in without the "admin" role (49ms) ✓ should not be able to save an article if not logged in ✓ should not be able to update an article if signed in without the "admin" role (52ms) ✓ should be able to get a list of articles if not signed in ✓ should be able to get a single article if not signed in ✓ should return proper error for single article with an invalid Id, if not signed in ✓ should return proper error for single article which doesnt exist, if not signed in ✓ should not be able to delete an article if signed in without the "admin" role (51ms) ✓ should not be able to delete an article if not signed in ✓ should be able to get a single article that has an orphaned user reference (140ms) ✓ should be able to get a single article if not signed in and verify the custom "isCurrentUserOwner" field is set to "false" ✓ should be able to get single article, that a different user created, if logged in & verify the "isCurrentUserOwner" field is set to "false" (225ms) Collection Model Unit Tests: Method Save 1) should be able to save without problems 2) should be able to show an error when try to save without name Collection CRUD tests 3) should be able to save a Collection if logged in ✓ should not be able to save an Collection if not logged in 4) should not be able to save an Collection if no name is provided 5) should be able to update an Collection if signed in ✓ should be able to get a list of Collections if not signed in ✓ should be able to get a single Collection if not signed in ✓ should return proper error for single Collection with an invalid Id, if not signed in ✓ should return proper error for single Collection which doesnt exist, if not signed in 6) should be able to delete an Collection if signed in ✓ should not be able to delete an Collection if not signed in 7) should be able to get a single Collection that has an orphaned user reference Configuration Tests: Testing default seedDB ✓ should have seedDB configuration set for "regular" user ✓ should have seedDB configuration set for admin user ✓ should not be an admin user to begin with ✓ should not be a "regular" user to begin with ✓ should seed ONLY the admin user account when NODE_ENV is set to "production" (42ms) ✓ should seed admin, and "regular" user accounts when NODE_ENV is set to "test" (83ms) ✓ should seed admin, and "regular" user accounts when NODE_ENV is set to "test" when they already exist (76ms) ✓ should ONLY seed admin user account when NODE_ENV is set to "production" with custom admin (38ms) ✓ should seed admin, and "regular" user accounts when NODE_ENV is set to "test" with custom options (132ms) ✓ should NOT seed admin user account if it already exists when NODE_ENV is set to "production" ✓ should NOT seed "regular" user account if missing email when NODE_ENV set to "test" Testing Session Secret Configuration ✓ should warn if using default session secret when running in production ✓ should accept non-default session secret when running in production ✓ should accept default session secret when running in development ✓ should accept default session secret when running in test Testing Logger Configuration ✓ should retrieve the log format from the logger configuration ✓ should retrieve the log options from the logger configuration for a valid stream object ✓ should verify that a file logger object was created using the logger configuration ✓ should use the default log format of "combined" when an invalid format was provided unable to find logging file configuration ✓ should not create a file transport object if critical options are missing: filename unable to find logging file configuration ✓ should not create a file transport object if critical options are missing: directory Testing exposing environment as a variable to layout ✓ should expose environment set to development (82ms) ✓ should expose environment set to production (64ms) ✓ should expose environment set to test (69ms) User Model Unit Tests: Method Save ✓ should begin with no users ✓ should be able to save without problems ✓ should fail to save an existing user again (79ms) ✓ should be able to show an error when trying to save without first name ✓ should be able to update an existing user with valid roles without problems ✓ should be able to show an error when trying to update an existing user without a role ✓ should be able to show an error when trying to update an existing user with a invalid role ✓ should confirm that saving user model doesnt change the password ✓ should be able to save 2 different users (73ms) ✓ should not be able to save another user with the same email address (70ms) ✓ should not index missing email field, thus not enforce the model's unique index (80ms) ✓ should not save the password in plain text ✓ should not save the passphrase in plain text (39ms) User Password Validation Tests ✓ should validate when the password strength passes - "P@$$w0rd!!" ✓ should validate a randomly generated passphrase from the static schema method ✓ should validate when the password is undefined ✓ should validate when the passphrase strength passes - "Open-Source Full-Stack Solution For MEAN Applications" ✓ should not allow a password less than 10 characters long - "P@$$w0rd!" ✓ should not allow a password greater than 128 characters long. ✓ should not allow a password with 3 or more repeating characters - "P@$$w0rd!!!" ✓ should not allow a password with no uppercase letters - "p@$$w0rd!!" ✓ should not allow a password with less than one number - "P@$$word!!" ✓ should not allow a password with less than one special character - "Passw0rdss" User E-mail Validation Tests ✓ should not allow invalid email address - "123" ✓ should not allow invalid email address - "123@123@123" ✓ should allow email address - "123@123" ✓ should not allow invalid email address - "123.com" ✓ should not allow invalid email address - "@123.com" ✓ should not allow invalid email address - "abc@abc@abc.com" ✓ should not allow invalid characters in email address - "abc~@#$%^&*()ef=@abc.com" ✓ should not allow space characters in email address - "abc def@abc.com" ✓ should not allow doudble quote characters in email address - "abc"def@abc.com" ✓ should not allow double dotted characters in email address - "abcdef@abc..com" ✓ should allow single quote characters in email address - "abc'def@abc.com" ✓ should allow valid email address - "abc@abc.com" ✓ should allow valid email address - "abc+def@abc.com" ✓ should allow valid email address - "abc.def@abc.com" ✓ should allow valid email address - "abc.def@abc.def.com" ✓ should allow valid email address - "abc-def@abc.com" Username Validation ✓ should show error to save username beginning with . ✓ should be able to show an error when try to save with not allowed username ✓ should show error to save username end with . ✓ should show error to save username with .. ✓ should show error to save username shorter than 3 character ✓ should show error saving a username without at least one alphanumeric character ✓ should show error saving a username longer than 34 characters ✓ should save username with dot User CRUD tests ✓ should be able to register a new user (48ms) ✓ should be able to login with username successfully and logout successfully (57ms) ✓ should be able to login with email successfully and logout successfully (67ms) ✓ should not be able to retrieve a list of users if not admin (47ms) ✓ should be able to retrieve a list of users if admin (499ms) ✓ should be able to get a single user details if admin (1273ms) ✓ should be able to update a single user details if admin (77ms) ✓ should be able to delete a single user if admin (52ms) ✓ forgot password should return 400 for non-existent username ✓ forgot password should return 400 for no username provided ✓ forgot password should return 400 for non-local provider set for the user object ✓ forgot password should be able to reset password for user password reset request (38ms) ✓ forgot password should be able to reset the password using reset token ✓ forgot password should return error when using invalid reset token ✓ should be able to change user own password successfully (130ms) ✓ should not be able to change user own password if wrong verifyPassword is given (88ms) ✓ should not be able to change user own password if wrong currentPassword is given (91ms) ✓ should not be able to change user own password if no new password is at all given (49ms) ✓ should not be able to change user own password if not signed in ✓ should be able to get own user details successfully (47ms) ✓ should not be able to get any user details if not logged in ✓ should be able to update own user details (77ms) ✓ should not be able to update own user details and add roles if not admin (60ms) ✓ should not be able to update own user details with existing username (87ms) ✓ should not be able to update own user details with existing email (104ms) ✓ should not be able to update secure fields (53ms) ✓ should not be able to update own user details if not logged-in ✓ should not be able to update own user profile picture without being logged-in ✓ should be able to change profile picture if signed in (77ms) ✓ should not be able to change profile picture if attach a picture with a different field name (57ms) ✓ should not be able to upload a non-image file as a profile picture (59ms) ✓ should not be able to change profile picture to too big of a file (58ms) 128 passing (10s) 7 failing 1) Collection Model Unit Tests: Method Save should be able to save without problems: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. at modules/collections/tests/server/collection.server.model.tests.js:46:9 at node_modules/mongoose/lib/model.js:3388:16 at node_modules/mongoose/lib/document.js:1997:18 at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickDomainCallback (internal/process/next_tick.js:122:9) 2) Collection Model Unit Tests: Method Save should be able to show an error when try to save without name: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. at modules/collections/tests/server/collection.server.model.tests.js:55:9 at node_modules/mongoose/lib/model.js:3388:16 at node_modules/mongoose/lib/document.js:2002:15 at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickDomainCallback (internal/process/next_tick.js:122:9) 3) Collection CRUD tests should be able to save a Collection if logged in: Error: expected 200 "OK", got 422 "Unprocessable Entity" at Test._assertStatus (node_modules/supertest/lib/test.js:266:12) at Test._assertFunction (node_modules/supertest/lib/test.js:281:11) at Test.assert (node_modules/supertest/lib/test.js:171:18) at Server.assert (node_modules/supertest/lib/test.js:131:12) at emitCloseNT (net.js:1555:8) at _combinedTickCallback (internal/process/next_tick.js:71:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9) 4) Collection CRUD tests should not be able to save an Collection if no name is provided: Error: expected 200 "OK", got 422 "Unprocessable Entity" at Test._assertStatus (node_modules/supertest/lib/test.js:266:12) at Test._assertFunction (node_modules/supertest/lib/test.js:281:11) at Test.assert (node_modules/supertest/lib/test.js:171:18) at Server.assert (node_modules/supertest/lib/test.js:131:12) at emitCloseNT (net.js:1555:8) at _combinedTickCallback (internal/process/next_tick.js:71:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9) 5) Collection CRUD tests should be able to update an Collection if signed in: Error: expected 200 "OK", got 422 "Unprocessable Entity" at Test._assertStatus (node_modules/supertest/lib/test.js:266:12) at Test._assertFunction (node_modules/supertest/lib/test.js:281:11) at Test.assert (node_modules/supertest/lib/test.js:171:18) at Server.assert (node_modules/supertest/lib/test.js:131:12) at emitCloseNT (net.js:1555:8) at _combinedTickCallback (internal/process/next_tick.js:71:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9) 6) Collection CRUD tests should be able to delete an Collection if signed in: Error: expected 200 "OK", got 422 "Unprocessable Entity" at Test._assertStatus (node_modules/supertest/lib/test.js:266:12) at Test._assertFunction (node_modules/supertest/lib/test.js:281:11) at Test.assert (node_modules/supertest/lib/test.js:171:18) at Server.assert (node_modules/supertest/lib/test.js:131:12) at emitCloseNT (net.js:1555:8) at _combinedTickCallback (internal/process/next_tick.js:71:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9) 7) Collection CRUD tests should be able to get a single Collection that has an orphaned user reference: Error: expected 200 "OK", got 422 "Unprocessable Entity" at Test._assertStatus (node_modules/supertest/lib/test.js:266:12) at Test._assertFunction (node_modules/supertest/lib/test.js:281:11) at Test.assert (node_modules/supertest/lib/test.js:171:18) at Server.assert (node_modules/supertest/lib/test.js:131:12) at emitCloseNT (net.js:1555:8) at _combinedTickCallback (internal/process/next_tick.js:71:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9)

cliffeby commented 7 years ago

These test failures have existed prior to the SERVER PATH issue in this thread. The following may be helpful:

Method Save should be able to save without problems: produced a -expected 200 but got 422 Unprocessable Entity- error. I believe it is due to the done() callback and the New Module Promise conflict. This blog provides a great explanation of issue and fixes.

http://staxmanade.com/2015/11/testing-asyncronous-code-with-mochajs-and-es7-async-await/