-
Notifications
You must be signed in to change notification settings - Fork 96
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
Update feathers-service-tests to version 0.8.1 π #124
Merged
+117
β52
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
import errors from 'feathers-errors'; | ||
|
||
export default function errorHandler (error) { | ||
let feathersError = error; | ||
|
||
if (error.name) { | ||
switch (error.name) { | ||
case 'ValidationError': | ||
case 'ValidatorError': | ||
case 'CastError': | ||
case 'VersionError': | ||
feathersError = new errors.BadRequest(error); | ||
break; | ||
return Promise.reject(new errors.BadRequest(error)); | ||
case 'OverwriteModelError': | ||
feathersError = new errors.Conflict(error); | ||
break; | ||
return Promise.reject(new errors.Conflict(error)); | ||
case 'MissingSchemaError': | ||
case 'DivergentArrayError': | ||
feathersError = new errors.GeneralError(error); | ||
break; | ||
return Promise.reject(new errors.GeneralError(error)); | ||
case 'MongoError': | ||
if (error.code === 11000) { | ||
feathersError = new errors.Conflict(error); | ||
} else { | ||
feathersError = new errors.GeneralError(error); | ||
return Promise.reject(new errors.Conflict(error)); | ||
} | ||
break; | ||
|
||
return Promise.rejct(new errors.GeneralError(error)); | ||
} | ||
} | ||
|
||
return Promise.reject(feathersError); | ||
return Promise.reject(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Pet from './pet'; | ||
import User from './user'; | ||
import Peeps from './peeps'; | ||
import CustomPeeps from './peeps-customid'; | ||
|
||
export default { | ||
Pet, User, Peeps, CustomPeeps | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import mongoose from 'mongoose'; | ||
const Schema = mongoose.Schema; | ||
|
||
const PeepsSchema = new Schema({ | ||
customid: { | ||
type: Schema.Types.ObjectId, | ||
default: function () { | ||
return new mongoose.Types.ObjectId(); | ||
} | ||
}, | ||
name: { type: String, required: true }, | ||
age: { type: Number }, | ||
created: {type: Boolean, 'default': false}, | ||
time: {type: Number} | ||
}); | ||
|
||
export default mongoose.model('PeepsCustomid', PeepsSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import mongoose from 'mongoose'; | ||
const Schema = mongoose.Schema; | ||
|
||
const PeepsSchema = new Schema({ | ||
name: { type: String, required: true }, | ||
age: { type: Number }, | ||
created: {type: Boolean, 'default': false}, | ||
time: {type: Number} | ||
}); | ||
|
||
export default mongoose.model('Peeps', PeepsSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@daffl Can you elaborate or add a more detailed comment on what this is actually doing? I know it fixes something but I don't really understand what this is for. Is there a test that this refers to?
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.
The test is https://github.com/feathersjs/feathers-service-tests/blob/master/src/common-tests.js#L525. Basically if you did something like
.patch(null, { name: 'Eric' }, { query: { name: 'David' } })
you didn't get events or the changed items. This is also not a complete fix but covers a fairly common case.There does not seem to be a way to get the actually changed items or at least the ids from MongoDB multi updates (or many other db adapters).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.
ok cool. Thanks! I added some more detail to the comment for future reference.
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.
Maybe the better fix is to make a
find
, run the update and then another find with the list of original ids viafind({ _id: { $in: oldFindIds } })
after.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.
@daffl probably. That would be easier to trace and also the way I would normally do it in my own code. However, it might be more expensive an operation than just doing what you are doing in memory. Especially if patching a lot of objects. We'd almost need to test with 10k documents or something.
A common use case for patches like that are database migrations so large numbers would be common.
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.
We could add a flag for that case. But in order to get real-time events there isn't really a way around returning all changed items. I think it makes sense to change the adapters to what I suggested because then it'll at least return only the changed items (right now it returns everything that matches the query).
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.
Oh I didn't notice that. You're right. It is better to do that. At least then we are dispatching for the correct records. We can optimize for speed later (it might not be bad, it could just use some testing).