Permalink
Browse files

Fix tests

  • Loading branch information...
1 parent 78e7c05 commit 7a28c32bc1f2324fed921f42d246aa661e63e447 @sgress454 sgress454 committed Jan 6, 2017
Showing with 6 additions and 7 deletions.
  1. +6 −7 test/integration/hook.pubsub.modelEvents.subscribers.test.js
@@ -175,7 +175,7 @@ describe('pubsub :: ', function() {
});
- it('adding a user to the pet via POST /user/1/pets should result in a correct `pet` event being received by all subscribers', function(done) {
+ it('adding a user to the pet via PUT /user/1/pets/1 should result in a correct `pet` event being received by all subscribers', function(done) {
socket1.on('pet', function(message) {
assert(message.id == 1 &&
@@ -184,9 +184,7 @@ describe('pubsub :: ', function() {
done();
});
- socket2.post('/user/1/pets', {
- pet_id: 1
- },function(body, jwr) {
+ socket2.put('/user/1/pets/1', {}, function(body, jwr) {
if (jwr.error) { return done(jwr.error); }
// Otherwise, the event handler above should fire (or this test will time out and fail).
});
@@ -210,7 +208,7 @@ describe('pubsub :: ', function() {
});
- it('creating a new pet and adding it via POST /user/1/pets should result in a `pet` event and a `user` event being received by all subscribers', function(done) {
+ it('creating a new pet and adding it via POST /pet should result in a `pet` event and a `user` event being received by all subscribers', function(done) {
var msgsReceived = 0;
// We should receive two 'user' updates: one from user #1 telling us they no longer have a profile, one
@@ -240,8 +238,9 @@ describe('pubsub :: ', function() {
// Subscribe to new pet notifications.
socket1.get('/pet', function() {
- socket2.post('/user/1/pets', {
- name: 'alice'
+ socket2.post('/pet', {
+ name: 'alice',
+ owner: 1
},function(body, jwr) {
if (jwr.error) { return done(jwr.error); }
// Otherwise, the event handler above should fire (or this test will time out and fail).

8 comments on commit 7a28c32

@luislobo
Contributor

@sgress454 I think this change should be added to https://github.com/balderdashy/sails-docs/blob/1.0/upgrading/To1.0.md if the behavior is not going to work with a POST

@sgress454
Member
sgress454 commented on 7a28c32 Jan 9, 2017 edited

@luislobo yup, it's in the tl;dr checklist (last item), and has an expanded section as well. If you have any suggestions about language, please let us know!

@luislobo
Contributor

I would mention something about changing the HTTP verb somewhere, like, instead of sending POST /user/1/pets you have to send PUT /user/1/pets/1.

One separate question, for "one-to-many" or even "many-to-many", does it support multiple items? or we need to send several PUT?

@sgress454
Member
sgress454 commented on 7a28c32 Jan 9, 2017 edited

@luislobo

I would mention something about changing the HTTP verb somewhere

Good call, added that to the TL;DR checklist and also updated some outdated docs.

does it support multiple items? or we need to send several PUT?

The replace blueprint always expects an array of primary keys (even if it's an empty array) as its input, which will be used to replace the current collection. So you only need to call it once.

@luislobo
Contributor

@sgress454 nice thanks!

@luislobo
Contributor

@sgress454
BTW, in https://github.com/balderdashy/sails-docs/blob/1.0/reference/blueprint-api/Replace.md , in the sample appears that the PUT code is wrong, the associations ID appear in a separate section. I don't want to change it because I don't know if the keys should go in the URL or in the body...

Another question. Does the Add support arrays too? then https://github.com/balderdashy/sails-docs/blob/1.0/reference/blueprint-api/Add.md should be updated.

Thank you!

@sgress454
Member

@luislobo Looks like there was a formatting issue in the "replace" doc, fixed now. As far "Add", the answer is no, it doesn't support arrays. You can only add a single record to an association with the add blueprint (same with remove).

@luislobo
Contributor

Ok thanks!

Please sign in to comment.