Skip to content

Disable inclusion of User.accessTokens - #1318

Merged
raymondfeng merged 1 commit into
masterfrom
feature/disable-include-access-tokens
Apr 21, 2015
Merged

raymondfeng merged 1 commit into
masterfrom
feature/disable-include-access-tokens

Conversation

@raymondfeng

Copy link
Copy Markdown
Member

/to @bajtos

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please build the app in test/user.integration.js and don't use loopback-boot?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why? The purpose of the user.integration.js is to test a LB app's built-in user model.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The purpose of the user.integration.js is to test a LB app's built-in user model.

As you wrote yourself, there is nothing related to loopback-boot in the scenario you are testing.

It is a good practice to write the test code in such way that it's easy to quickly understand what is the scenario being tested. The test scenario should be also as minimal as possible and include only things that are absolutely necessary for the test.

By using a fixture defined in several files living outside of the test file, you are making it difficult to understand what is exactly being tested. By including lots of unrelated stuff in your fixture, you make it difficult to see what is the important (test-specific) part and what is just boilerplate. Last but not least, all these extra unneeded bits are making the maintenance more expensive.

This is already visible in this pull request, as the server/server.js file is not following the project structure as scaffolded by recent versions of loopback-workspace.

To test the built-in user model, you need just few lines of code:

var app = loopback();
app.dataSource('db', { connector: 'memory' });
app.model(loopback.User, { dataSource: 'db' });
app.model(loopback.AccessToken, { dataSource: 'db' });
app.model(loopback.ACL, { dataSource: 'db' });
app.model(loopback.Role, { dataSource: 'db' });
app.model(loopback.RoleMapping, { dataSource: 'db' }); // this may be not necessary

app.enableAuth();

app.use(loopback.rest());
request = supertest(app);

I admit this setup is not as short as it should be, let's discuss the best API in #1323 and keep the code above for the purposes of this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are more models such as post and blog are needed. I'll merge the PR as is and defer the cleanup of tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am rather unhappy that you have added tests that always pass, regardless of whether the underlying implementation works or not. Such tests are giving false sense of security 👎

raymondfeng added a commit that referenced this pull request Apr 21, 2015
…ss-tokens

Disable inclusion of User.accessTokens
@raymondfeng
raymondfeng merged commit a4121ee into master Apr 21, 2015
@raymondfeng
raymondfeng deleted the feature/disable-include-access-tokens branch April 21, 2015 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants