FFFF Test and fix for allowing services with only a setup method by daffl · Pull Request #308 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default {

// Run the provider functions to register the service
this.providers.forEach(provider =>
provider.call(this, location, protoService, options));
provider.call(this, location, protoService, options)
);

// If we ran setup already, set this service up explicitly
if (this._isSetup && typeof protoService.setup === 'function') {
Expand Down Expand Up @@ -75,10 +76,11 @@ export default {
});

const hasMethod = methods => methods.some(name =>
(service && typeof service[name] === 'function'));
(service && typeof service[name] === 'function')
);

// Check for service (any object with at least one service method)
if(hasMethod(['handle', 'set']) || !hasMethod(this.methods)) {
if(hasMethod(['handle', 'set']) || !hasMethod(this.methods.concat('setup'))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to throw an error or a debug warning in case the service doesn't have a setup method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Services without a setup method shouldn't be a problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I made that comment I realized it didn't make sense. PROCEED! 😄

return this._super.apply(this, arguments);
}

Expand Down
14 changes: 14 additions & 0 deletions test/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@ describe('Feathers application', () => {
assert.equal(otherApp.mixins.length, 4);
});

it('initializes a service with only a setup method (#285)', done => {
const app = feathers();

app.use('/setup-only', {
setup(_app, path) {
assert.equal(_app, app);
assert.equal(path, 'setup-only');
done();
}
});

app.setup();
});

it('Event punching happens after normalization (#150)', done => {
const todoService = {
create(data) {
Expand Down
0