-
Notifications
You must be signed in to change notification settings - Fork 43
move sample realtime events for put/patch/delete to api layer #294
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,32 +92,49 @@ function publishObject(inst, event, changedKeys, ignoreAttributes) { | |
| * a absolutePath field added to it before the sample is published to the redis | ||
| * channel. | ||
| * @param {Object} sampleInst - The sample instance to be published | ||
| * @param {Model} model - The subject model used to get the related subject | ||
| * instance | ||
| * @param {Model} subjectModel - The subject model to get the related | ||
| * subject instance | ||
| * @param {String} event - Type of the event that is being published | ||
| * @param {Model} aspectModel - The aspect model to get the related | ||
| * aspect instance | ||
| * @returns {Promise} - which resolves to a sample object | ||
| */ | ||
| function publishSample(sampleInst, model, event) { | ||
| function publishSample(sampleInst, subjectModel, event, aspectModel) { | ||
| const eventType = event || getSampleEventType(sampleInst); | ||
| const sample = sampleInst.get ? sampleInst.get() : sampleInst; | ||
| const subName = sample.name.split('|')[0]; | ||
| const options = {}; | ||
| options.where = { absolutePath: subName }; | ||
| return model.findOne(options) | ||
| const nameParts = sample.name.split('|'); | ||
| const subName = nameParts[0]; | ||
| const aspName = nameParts[1]; | ||
| const subOpts = { | ||
| where: { | ||
| absolutePath: subName, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. case insensitive? |
||
| }, | ||
| }; | ||
| const aspOpts = { | ||
| where: { | ||
| name: aspName, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. case insensitive?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aspectName and subjectName are always from the "sample.name" field from the db and the "sample.name" field is formed from its subject and its aspect in the db. So the case always matches when we do the find here. |
||
| }, | ||
| }; | ||
| const getAspect = aspectModel ? aspectModel.findOne(aspOpts) : | ||
| Promise.resolve(sample.aspect); | ||
| return getAspect | ||
| .then((asp) => { | ||
| sample.aspect = asp.get ? asp.get() : asp; | ||
| return subjectModel.findOne(subOpts); | ||
| }) | ||
| .then((sub) => { | ||
| if (sub) { | ||
|
|
||
| /* | ||
| *pass the sample instance to the publishObject function only if the | ||
| *aspect and subject are published | ||
| */ | ||
| if (sample.aspect && sample.aspect.isPublished && sub.isPublished) { | ||
|
|
||
| // attach subject to the sample | ||
| sample.subject = sub.get(); | ||
|
|
||
| // attach absolutePath field to the sample | ||
| sample.absolutePath = subName; | ||
|
|
||
| publishObject(sample, eventType); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| */ | ||
|
|
||
| /** | ||
| * tests/realtime/setupSocketIO.js | ||
| * tests/realtime/redisPublisher.js | ||
| */ | ||
| 'use strict'; | ||
|
|
||
|
|
@@ -81,6 +81,29 @@ describe('redis Publisher', () => { | |
| }) | ||
| .catch(done); | ||
| }); | ||
|
|
||
| it('when tried to publish sample without aspect,'+ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any other tests we can add here to make sure that we aren't breaking any of the existing realtime event publishing?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sample object the is finally passed to the real-time emitter should have the following fields/objects to not to break anything
|
||
| ' aspect should be attached', (done) => { | ||
| Sample.findById(sampId) | ||
| .then((sam) => { | ||
| const sampInst = sam.get(); | ||
| delete sampInst.aspect; | ||
| return publisher.publishSample(sam, Subject, sampleEvent.upd, Aspect); | ||
| }) | ||
| .then((pubObj) => { | ||
| expect(pubObj.aspect).to.not.equal(null); | ||
| expect(pubObj.aspect.name).to.equal(humidity.name); | ||
| expect(pubObj.aspect.tags.length).to.equal(0); | ||
| expect(pubObj.subject).to.not.equal(null); | ||
| expect(pubObj.subject.name).to.equal(subjectNA.name); | ||
| expect(pubObj.subject.tags.length).to.equal(0); | ||
| expect(pubObj.absolutePath).to.equal(subjectNA.name); | ||
| expect(pubObj.aspect.tags.length).to.equal(0); | ||
|
|
||
| done(); | ||
| }) | ||
| .catch(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getSampleEventType function tests: ', () => { | ||
|
|
@@ -115,5 +138,4 @@ describe('redis Publisher', () => { | |
| .catch(done); | ||
| }); | ||
| }); | ||
|
|
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we test for whether a sample is published on realtime create and delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another story for this.