replaced eslint:recommended with prettier

This commit is contained in:
Wyatt Johnson
2018-01-11 20:00:34 -07:00
parent d56c19016a
commit 0abc2ca243
649 changed files with 16235 additions and 13008 deletions
+43 -25
View File
@@ -1,4 +1,4 @@
const {graphql} = require('graphql');
const { graphql } = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
@@ -7,42 +7,44 @@ const SettingsService = require('../../../../services/settings');
const Asset = require('../../../../models/asset');
const CommentsService = require('../../../../services/comments');
const {expect} = require('chai');
const { expect } = require('chai');
describe('graph.queries.asset', () => {
let assets, users, comments;
beforeEach(async () => {
await SettingsService.init();
assets = await Asset.create([
{id: '1', url: 'https://example.com/?id=1'},
{id: '2', url: 'https://example.com/?id=2'}
{ id: '1', url: 'https://example.com/?id=1' },
{ id: '2', url: 'https://example.com/?id=2' },
]);
users = await UsersService.createLocalUsers([
{
email: 'usernameA@example.com',
password: 'password',
username: 'usernameA'
username: 'usernameA',
},
{
email: 'usernameB@example.com',
password: 'password',
username: 'usernameB'
username: 'usernameB',
},
{
email: 'usernameC@example.com',
password: 'password',
username: 'usernameC'
}
username: 'usernameC',
},
]);
comments = await CommentsService.publicCreate([0, 0, 1, 1].map((idx) => ({
author_id: users[idx].id,
asset_id: assets[idx].id,
body: `hello there! ${String(Math.random()).slice(2)}`,
})));
comments = await CommentsService.publicCreate(
[0, 0, 1, 1].map(idx => ({
author_id: users[idx].id,
asset_id: assets[idx].id,
body: `hello there! ${String(Math.random()).slice(2)}`,
}))
);
});
it('will not show the same asset stream across multiple assets', async () => {
const context = new Context({user: users[0]});
const context = new Context({ user: users[0] });
const query = `
fragment assetFragment on Asset {
@@ -64,20 +66,30 @@ describe('graph.queries.asset', () => {
}
`;
let res = await graphql(schema, query, {}, context, {id: assets[0].id, otherID: assets[1].id});
let res = await graphql(schema, query, {}, context, {
id: assets[0].id,
otherID: assets[1].id,
});
if (res.errors) {
console.error(res.errors);
}
expect(res.errors).is.empty;
let {asset: {comments: asset}, otherAsset: {comments: otherAsset}} = res.data;
let {
asset: { comments: asset },
otherAsset: { comments: otherAsset },
} = res.data;
expect(asset.nodes).to.have.length(2);
expect(asset.hasNextPage).to.be.false;
expect(asset.nodes.map(({id}) => id)).to.have.members(comments.slice(0, 2).map(({id}) => id));
expect(asset.nodes.map(({ id }) => id)).to.have.members(
comments.slice(0, 2).map(({ id }) => id)
);
expect(otherAsset.nodes).to.have.length(2);
expect(otherAsset.hasNextPage).to.be.false;
expect(otherAsset.nodes.map(({id}) => id)).to.have.members(comments.slice(2, 4).map(({id}) => id));
expect(otherAsset.nodes.map(({ id }) => id)).to.have.members(
comments.slice(2, 4).map(({ id }) => id)
);
for (let node of asset.nodes) {
for (let otherNode of otherAsset.nodes) {
@@ -87,7 +99,7 @@ describe('graph.queries.asset', () => {
});
it('can get comments edge', async () => {
const context = new Context({user: users[0]});
const context = new Context({ user: users[0] });
const assetCommentsQuery = `
query assetCommentsQuery($id: ID!) {
@@ -105,8 +117,15 @@ describe('graph.queries.asset', () => {
}
}
`;
const res = await graphql(schema, assetCommentsQuery, {}, context, {id: assets[0].id});
const {nodes, startCursor, endCursor, hasNextPage} = res.data.asset.comments;
const res = await graphql(schema, assetCommentsQuery, {}, context, {
id: assets[0].id,
});
const {
nodes,
startCursor,
endCursor,
hasNextPage,
} = res.data.asset.comments;
expect(nodes.length).to.equal(2);
expect(startCursor).to.equal(nodes[0].created_at);
expect(endCursor).to.equal(nodes[1].created_at);
@@ -114,7 +133,7 @@ describe('graph.queries.asset', () => {
});
it('can query comments edge to exclude comments ignored by user', async () => {
const context = new Context({user: users[0]});
const context = new Context({ user: users[0] });
// Add the second user to the list of ignored users.
context.user.ignoresUsers.push(users[1].id);
@@ -136,12 +155,11 @@ describe('graph.queries.asset', () => {
const res = await graphql(schema, query, {}, context, {
id: assets[0].id,
url: assets[0].url,
excludeIgnored: true
excludeIgnored: true,
});
expect(res.errors).is.empty;
const {nodes} = res.data.asset.comments;
const { nodes } = res.data.asset.comments;
expect(nodes.length).to.equal(2);
}
});
});
+10 -12
View File
@@ -1,14 +1,14 @@
const {graphql} = require('graphql');
const { graphql } = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
const SettingsService = require('../../../../services/settings');
const UserModel = require('../../../../models/user');
const {expect} = require('chai');
const { expect } = require('chai');
const defaultSettings = {
organizationName: 'The Coral Project'
organizationName: 'The Coral Project',
};
describe('graph.queries.settings', () => {
@@ -47,7 +47,6 @@ describe('graph.queries.settings', () => {
`;
describe('context with different user roles', () => {
const BLACKLISTED_PROPERTIES = [
'premodLinksEnable',
'autoCloseStream',
@@ -56,13 +55,13 @@ describe('graph.queries.settings', () => {
];
[
{bl: true, role: 'COMMENTER'},
{bl: false, role: 'ADMIN'},
{bl: false, role: 'MODERATOR'},
].forEach(({bl, role}) => {
{ bl: true, role: 'COMMENTER' },
{ bl: false, role: 'ADMIN' },
{ bl: false, role: 'MODERATOR' },
].forEach(({ bl, role }) => {
it(`role = ${role}`, async () => {
let user = new UserModel({role});
const ctx = new Context({user});
let user = new UserModel({ role });
const ctx = new Context({ user });
const res = await graphql(schema, QUERY, {}, ctx);
if (res.errors) {
@@ -71,7 +70,7 @@ describe('graph.queries.settings', () => {
expect(res.errors).to.be.empty;
expect(res.data.settings).to.be.object;
Object.keys(res.data.settings).forEach((key) => {
Object.keys(res.data.settings).forEach(key => {
if (bl && BLACKLISTED_PROPERTIES.includes(key)) {
expect(res.data.settings).to.have.property(key, null);
return;
@@ -87,5 +86,4 @@ describe('graph.queries.settings', () => {
});
});
});
});
+17 -14
View File
@@ -1,4 +1,4 @@
const {graphql} = require('graphql');
const { graphql } = require('graphql');
const schema = require('../../../../graph/schema');
const Context = require('../../../../graph/context');
@@ -8,18 +8,21 @@ const UsersService = require('../../../../services/users');
const chai = require('chai');
chai.use(require('chai-datetime'));
const {expect} = chai;
const { expect } = chai;
describe('graph.queries.user', () => {
let user;
beforeEach(async () => {
await SettingsService.init();
user = await UsersService.createLocalUser('usernameA@example.com', 'password', 'usernameA');
user = await UsersService.createLocalUser(
'usernameA@example.com',
'password',
'usernameA'
);
});
describe('state', () => {
const meQuery = `
query Me {
me {
@@ -35,9 +38,9 @@ describe('graph.queries.user', () => {
`;
it('can query me', async () => {
const ctx = new Context({user});
const ctx = new Context({ user });
const {data, errors} = await graphql(schema, meQuery, {}, ctx);
const { data, errors } = await graphql(schema, meQuery, {}, ctx);
expect(errors).to.be.undefined;
expect(data.me).to.not.be.null;
@@ -60,16 +63,16 @@ describe('graph.queries.user', () => {
`;
[
{role: 'COMMENTER', can: false},
{role: 'STAFF', can: false},
{role: 'MODERATOR', can: true},
{role: 'ADMIN', can: true},
].forEach(({role, can}) => {
{ role: 'COMMENTER', can: false },
{ role: 'STAFF', can: false },
{ role: 'MODERATOR', can: true },
{ role: 'ADMIN', can: true },
].forEach(({ role, can }) => {
it(`${can ? 'can' : 'can not'} query with role = ${role}`, async () => {
const actor = new UserModel({role});
const ctx = new Context({user: actor});
const actor = new UserModel({ role });
const ctx = new Context({ user: actor });
const {data, errors} = await graphql(schema, query, {}, ctx, {
const { data, errors } = await graphql(schema, query, {}, ctx, {
user_id: user.id,
});