diff --git a/frontend/components/KeyboardShortcuts/KeyboardShortcuts.js b/frontend/components/KeyboardShortcuts/KeyboardShortcuts.js
index c8aa58b5a..8aeb5f606 100644
--- a/frontend/components/KeyboardShortcuts/KeyboardShortcuts.js
+++ b/frontend/components/KeyboardShortcuts/KeyboardShortcuts.js
@@ -12,7 +12,7 @@ function KeyboardShortcuts() {
return (
- Atlas is designed to be super fast and easy to use.
+ Atlas is designed to be super fast and easy to use.
All of your usual keyboard shortcuts work here.
diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js
index 08f589e14..e26d3f9f1 100644
--- a/frontend/scenes/Document/Document.js
+++ b/frontend/scenes/Document/Document.js
@@ -171,6 +171,7 @@ type Props = {
const isEditing = !!this.props.match.params.edit || isNew;
const isFetching = !this.document;
const titleText = get(this.document, 'title', 'Loading');
+ const document = this.document;
return (
@@ -185,9 +186,9 @@ type Props = {
}
{!isFetching &&
- this.document &&
+ document &&
@@ -225,7 +226,7 @@ type Props = {
/>
: Edit}
- {!isEditing && }
+ {!isEditing && }
diff --git a/frontend/utils/__mocks__/ApiClient.js b/frontend/utils/__mocks__/ApiClient.js
index d53d1d2dc..6ee89e52f 100644
--- a/frontend/utils/__mocks__/ApiClient.js
+++ b/frontend/utils/__mocks__/ApiClient.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
export default {
client: {
post: jest.fn(() => Promise.resolve),
diff --git a/package.json b/package.json
index 5071b870a..ddaee03b6 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"sequelize:migrate": "sequelize db:migrate",
"test": "npm run test:frontend && npm run test:server",
"test:frontend": "jest",
- "test:server": "jest --config=server/.jestconfig.json --runInBand",
+ "test:server": "jest --config=server/.jestconfig.json --runInBand --forceExit",
"precommit": "lint-staged"
},
"lint-staged": {
@@ -48,7 +48,7 @@
"frontend"
],
"setupFiles": [
- "/frontend/utils/setupJest.js",
+ "/setupJest.js",
"/__mocks__/window.js"
]
},
diff --git a/server/api/auth.js b/server/api/auth.js
index 8ae10466a..811055cf5 100644
--- a/server/api/auth.js
+++ b/server/api/auth.js
@@ -91,7 +91,7 @@ router.post('auth.slack', async ctx => {
const body = {
client_id: process.env.SLACK_KEY,
client_secret: process.env.SLACK_SECRET,
- redirect_uri: `${process.env.URL}/auth/slack`,
+ redirect_uri: `${process.env.URL || ''}/auth/slack`,
code,
};
@@ -108,7 +108,8 @@ router.post('auth.slack', async ctx => {
if (!data.ok) throw httpErrors.BadRequest(data.error);
// Temp to block
- const allowedSlackDomains = process.env.ALLOWED_SLACK_DOMAINS.split(',');
+ const allowedSlackDomains = (process.env.ALLOWED_SLACK_DOMAINS || '')
+ .split(',');
if (!allowedSlackDomains.includes(data.team.domain)) {
throw apiError(
400,
@@ -171,7 +172,7 @@ router.post('auth.slackCommands', async ctx => {
const body = {
client_id: process.env.SLACK_KEY,
client_secret: process.env.SLACK_SECRET,
- redirect_uri: `${process.env.URL}/auth/slack/commands`,
+ redirect_uri: `${process.env.URL || ''}/auth/slack/commands`,
code,
};
diff --git a/server/api/auth.test.js b/server/api/auth.test.js
index 114e0bf19..5da560065 100644
--- a/server/api/auth.test.js
+++ b/server/api/auth.test.js
@@ -6,7 +6,7 @@ import { flushdb, seed } from '../test/support';
const server = new TestServer(app.callback());
beforeEach(flushdb);
-afterAll(() => server.close());
+afterAll(server.close);
describe.skip('#auth.signup', async () => {
it('should signup a new user', async () => {
diff --git a/server/api/documents.js b/server/api/documents.js
index 282368408..36accaf2d 100644
--- a/server/api/documents.js
+++ b/server/api/documents.js
@@ -13,12 +13,13 @@ router.post('documents.list', auth(), pagination(), async ctx => {
if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user;
- const documents = await Document.findAll({
+ const userId = user.id;
+ const starredScope = { method: ['withStarred', userId] };
+ const documents = await Document.scope('defaultScope', starredScope).findAll({
where: { teamId: user.teamId },
order: [[sort, direction]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
- include: [{ model: Star, as: 'starred', where: { userId: user.id } }],
});
const data = await Promise.all(
diff --git a/server/api/documents.test.js b/server/api/documents.test.js
index 54f1728fd..000b45bb7 100644
--- a/server/api/documents.test.js
+++ b/server/api/documents.test.js
@@ -6,7 +6,7 @@ import { flushdb, seed } from '../test/support';
const server = new TestServer(app.callback());
beforeEach(flushdb);
-afterAll(() => server.close());
+afterAll(server.close);
describe('#documents.list', async () => {
it('should return documents', async () => {
diff --git a/server/api/user.test.js b/server/api/user.test.js
index 7c35cae8e..765d76a9c 100644
--- a/server/api/user.test.js
+++ b/server/api/user.test.js
@@ -3,12 +3,12 @@ import TestServer from 'fetch-test-server';
import app from '..';
import { User } from '../models';
-import { flushdb, seed, sequelize } from '../test/support';
+import { flushdb, seed } from '../test/support';
const server = new TestServer(app.callback());
beforeEach(flushdb);
-afterAll(() => server.close());
+afterAll(server.close);
describe('#user.info', async () => {
it('should return known user', async () => {
diff --git a/server/models/Document.js b/server/models/Document.js
index 1cf4a5b94..363f164bb 100644
--- a/server/models/Document.js
+++ b/server/models/Document.js
@@ -130,6 +130,11 @@ Document.associate = models => {
},
{ override: true }
);
+ Document.addScope('withStarred', userId => ({
+ include: [
+ { model: models.Star, as: 'starred', where: { userId }, required: false },
+ ],
+ }));
};
Document.findById = async id => {
diff --git a/server/models/User.test.js b/server/models/User.test.js
index db155667e..f9326f890 100644
--- a/server/models/User.test.js
+++ b/server/models/User.test.js
@@ -1,18 +1,9 @@
-import { User } from '.';
-
-import { flushdb, sequelize } from '../test/support';
+import { flushdb, seed } from '../test/support';
beforeEach(flushdb);
it('should set JWT secret and password digest', async () => {
- const user = User.build({
- username: 'user',
- name: 'User',
- email: 'user1@example.com',
- password: 'test123!',
- });
- await user.save();
-
+ const { user } = await seed();
expect(user.passwordDigest).toBeTruthy();
expect(user.getJwtToken()).toBeTruthy();
diff --git a/server/test/support.js b/server/test/support.js
index 128ede92e..33f915095 100644
--- a/server/test/support.js
+++ b/server/test/support.js
@@ -45,10 +45,10 @@ const seed = async () => {
type: 'atlas',
});
- let document = await Document.create({
+ const document = await Document.create({
parentDocumentId: null,
atlasId: collection.id,
- teamId: collection.teamId,
+ teamId: team.id,
userId: collection.creatorId,
lastModifiedById: collection.creatorId,
createdById: collection.creatorId,
diff --git a/frontend/utils/setupJest.js b/setupJest.js
similarity index 77%
rename from frontend/utils/setupJest.js
rename to setupJest.js
index 61b717c2f..b7cd60686 100644
--- a/frontend/utils/setupJest.js
+++ b/setupJest.js
@@ -1,8 +1,7 @@
-/* eslint-disable */
import React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
-import localStorage from '../../__mocks__/localStorage';
+import localStorage from './__mocks__/localStorage';
const snap = children => {
const wrapper = shallow(children);