mirror of
https://github.com/wassname/talk.git
synced 2026-07-29 11:28:24 +08:00
Updated linting rules + fixed test layout to standardize
This commit is contained in:
+14
-1
@@ -45,6 +45,19 @@
|
||||
"space-infix-ops": ["error"],
|
||||
"no-const-assign": [2],
|
||||
"no-duplicate-imports": [2],
|
||||
"prefer-template": [1]
|
||||
"prefer-template": [1],
|
||||
"comma-spacing": [
|
||||
"error",
|
||||
{
|
||||
"after": true
|
||||
}
|
||||
],
|
||||
"no-var": [2],
|
||||
"no-lonely-if": [2],
|
||||
"curly": [2],
|
||||
"no-multiple-empty-lines": [
|
||||
"error",
|
||||
{"max": 1}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ const ActionSchema = new Schema({
|
||||
item_type: String,
|
||||
item_id: String,
|
||||
user_id: String
|
||||
},{
|
||||
}, {
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
|
||||
+4
-7
@@ -25,7 +25,7 @@ const AssetSchema = new Schema({
|
||||
subsection: String,
|
||||
authors: [String],
|
||||
publication_date: Date
|
||||
},{
|
||||
}, {
|
||||
versionKey: false,
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
@@ -33,7 +33,6 @@ const AssetSchema = new Schema({
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Search for assets. Currently only returns all.
|
||||
*/
|
||||
@@ -58,12 +57,11 @@ AssetSchema.statics.findById = function(id) {
|
||||
* @param {String} url identifier of the asset (uuid).
|
||||
*/
|
||||
AssetSchema.statics.findByUrl = function(url) {
|
||||
|
||||
|
||||
return Asset.findOne({'url': url}).exec();
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Upserts an asset.
|
||||
*/
|
||||
@@ -88,7 +86,7 @@ AssetSchema.statics.upsert = function(data) {
|
||||
//return new Promise(); // ??? what do we return on error?
|
||||
|
||||
});
|
||||
|
||||
|
||||
return updatePromise;
|
||||
|
||||
};
|
||||
@@ -98,12 +96,11 @@ AssetSchema.statics.upsert = function(data) {
|
||||
* @param {String} query bson query to identify assets to be removed.
|
||||
*/
|
||||
AssetSchema.statics.removeAll = function(query) {
|
||||
|
||||
|
||||
return Asset.remove(query).exec();
|
||||
|
||||
};
|
||||
|
||||
|
||||
const Asset = mongoose.model('Asset', AssetSchema);
|
||||
|
||||
module.exports = Asset;
|
||||
|
||||
+1
-2
@@ -21,7 +21,7 @@ const CommentSchema = new Schema({
|
||||
default: ''
|
||||
},
|
||||
parent_id: String
|
||||
},{
|
||||
}, {
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
@@ -44,7 +44,6 @@ CommentSchema.statics.findByAssetId = function(asset_id) {
|
||||
return Comment.find({asset_id});
|
||||
};
|
||||
|
||||
|
||||
const Comment = mongoose.model('Comment', CommentSchema);
|
||||
|
||||
module.exports = Comment;
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ const UserProfileSchema = new Schema({
|
||||
},
|
||||
display_name: String,
|
||||
auth_user_id: String
|
||||
},{
|
||||
}, {
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ if (enabled('talk:db')) {
|
||||
|
||||
try {
|
||||
mongoose.connect(url, (err) => {
|
||||
if (err) throw err;
|
||||
if (err) {throw err;}
|
||||
console.log('Connected to MongoDB!');
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
@@ -41,5 +41,4 @@ router.put('/', (req, res, next) => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -7,7 +7,6 @@ const router = express.Router();
|
||||
// Routes
|
||||
//==============================================================================
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.send('Read all of the comments ever');
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ router.get('/', (req, res, next) => {
|
||||
Action.findByItemIdArray(comments.map((comment) => comment.id))
|
||||
]);
|
||||
}).then(([comments, users, actions]) => {
|
||||
res.json([...comments,...users,...actions]);
|
||||
res.json([...comments, ...users, ...actions]);
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
"node": true,
|
||||
"mocha": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"extends": "../.eslintrc.json",
|
||||
"rules": {
|
||||
"no-undef": [0]
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
/* eslint-env node, mocha */
|
||||
'use strict';
|
||||
|
||||
// require('./utils/mongoose')
|
||||
const expect = require('chai').expect;
|
||||
|
||||
|
||||
describe('Comment', () => {
|
||||
describe('#add', () => {
|
||||
it('should add a comment', () => {
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
require('../utils/mongoose');
|
||||
|
||||
const Action = require('../../models/action');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('Action: models', () => {
|
||||
var mockActions;
|
||||
let mockActions;
|
||||
beforeEach(() => {
|
||||
return Action.create([{
|
||||
action_type: 'flag',
|
||||
item_id: '123'
|
||||
},{
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: '789'
|
||||
},{
|
||||
}, {
|
||||
action_type: 'flag',
|
||||
item_id: '456'
|
||||
}]).then((actions) => {
|
||||
@@ -32,7 +31,7 @@ describe('Action: models', () => {
|
||||
|
||||
describe('#findByItemIdArray()', () => {
|
||||
it('should find an array of actions from an array of item_ids', () => {
|
||||
return Action.findByItemIdArray(['123','456']).then((result) => {
|
||||
return Action.findByItemIdArray(['123', '456']).then((result) => {
|
||||
expect(result).to.have.length(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
/* eslint-env node, mocha */
|
||||
const Asset = require('../models/asset');
|
||||
require('../utils/mongoose');
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const chai = require('chai');
|
||||
const chaiHttp = require('chai-http');
|
||||
const server = require('../app');
|
||||
const should = chai.should();
|
||||
should; // nullop to satisfy linting
|
||||
const expect = chai.expect;
|
||||
const server = require('../../app');
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Setup chai.
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
var fixture = {
|
||||
let fixture = {
|
||||
'url': 'http://hhgg.com/total-perspective-vortex',
|
||||
'type': 'article',
|
||||
'headline': 'The Total Perspective Vortex',
|
||||
@@ -19,23 +17,10 @@ var fixture = {
|
||||
'authors': ['Ford Prefect']
|
||||
};
|
||||
|
||||
describe('Asset: models', () => {
|
||||
|
||||
describe('Asset', () => {
|
||||
|
||||
beforeEach((done) => {
|
||||
|
||||
// TODO: implement asset remove
|
||||
Asset.removeAll({})
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
Asset; // nullop to satisfy linting.
|
||||
|
||||
});
|
||||
|
||||
describe('/GET Asset', () => {
|
||||
describe.only('#get', () => {
|
||||
describe('#get', () => {
|
||||
it('It should get an empty array when there are no assets.', (done) => {
|
||||
|
||||
chai.request(server)
|
||||
@@ -58,7 +43,7 @@ describe('Asset', () => {
|
||||
|
||||
// This test checks PUT and read
|
||||
describe('/PUT Asset', () => {
|
||||
describe.only('#put', () => {
|
||||
describe('#put', () => {
|
||||
it('It should save an asset and load it again.', (done) => {
|
||||
|
||||
chai.request(server)
|
||||
@@ -81,7 +66,7 @@ describe('Asset', () => {
|
||||
|
||||
// Load the asset to make sure it's really there.
|
||||
chai.request(server)
|
||||
.get('/api/v1/asset?url=' + fixture.url)
|
||||
.get(`/api/v1/asset?url=${encodeURIComponent(fixture.url)}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) {
|
||||
@@ -94,9 +79,9 @@ describe('Asset', () => {
|
||||
let asset = res.body[0];
|
||||
|
||||
expect(asset).to.have.property('id');
|
||||
|
||||
|
||||
// Ensure the asset has the same id as above.
|
||||
// This tests the single url per Id concept.
|
||||
// This tests the single url per Id concept.
|
||||
expect(assetId).to.equal(asset.id);
|
||||
|
||||
done();
|
||||
@@ -1,20 +1,18 @@
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
require('../utils/mongoose');
|
||||
|
||||
const Comment = require('../../models/comment');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('Comment: models', () => {
|
||||
var mockComments;
|
||||
let mockComments;
|
||||
beforeEach(() => {
|
||||
return Comment.create([{
|
||||
body: 'comment 10',
|
||||
asset_id: '123'
|
||||
},{
|
||||
}, {
|
||||
body: 'comment 20',
|
||||
asset_id: '123'
|
||||
},{
|
||||
}, {
|
||||
body: 'comment 30',
|
||||
asset_id: '456'
|
||||
}]).then((comments) => {
|
||||
@@ -35,7 +33,7 @@ describe('Comment: models', () => {
|
||||
it('should find an array of comments by asset id', () => {
|
||||
return Comment.findByAssetId('123').then((result) => {
|
||||
expect(result).to.have.length(2);
|
||||
result.sort((a,b) => {
|
||||
result.sort((a, b) => {
|
||||
if (a.body < b.body) {return -1;}
|
||||
else {return 1;}
|
||||
});
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
/* eslint-env node, mocha */
|
||||
|
||||
require('../utils/mongoose');
|
||||
|
||||
const User = require('../../models/user');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('User: models', () => {
|
||||
var mockUsers;
|
||||
let mockUsers;
|
||||
beforeEach(() => {
|
||||
return User.create([{
|
||||
display_name: 'Stampi',
|
||||
},{
|
||||
}, {
|
||||
display_name: 'Sockmonster',
|
||||
},{
|
||||
}, {
|
||||
display_name: 'Marvel',
|
||||
}]).then((users) => {
|
||||
mockUsers = users;
|
||||
@@ -29,12 +28,10 @@ describe('User: models', () => {
|
||||
|
||||
describe('#findByIdArray()', () => {
|
||||
it('should find an array of users from an array of ids', () => {
|
||||
const ids = mockUsers.map((user) => user.id)
|
||||
const ids = mockUsers.map((user) => user.id);
|
||||
return User.findByIdArray(ids).then((result) => {
|
||||
expect(result).to.have.length(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// });
|
||||
});
|
||||
|
||||
@@ -4,10 +4,11 @@ require('../../../utils/mongoose');
|
||||
|
||||
const app = require('../../../../app');
|
||||
const chai = require('chai');
|
||||
const chaiHttp = require('chai-http');
|
||||
chai.use(chaiHttp);
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
// Setup chai.
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const Comment = require('../../../../models/comment');
|
||||
const Action = require('../../../../models/action');
|
||||
@@ -17,36 +18,36 @@ describe('Post /comments', () => {
|
||||
const users = [{
|
||||
id: '123',
|
||||
display_name: 'John',
|
||||
},{
|
||||
}, {
|
||||
id: '456',
|
||||
display_name: 'Paul',
|
||||
}]
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
item_id: 'abc'
|
||||
},{
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: 'hij'
|
||||
}]
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return User.create(users).then(() => {
|
||||
return Action.create(actions)
|
||||
})
|
||||
})
|
||||
return Action.create(actions);
|
||||
});
|
||||
});
|
||||
|
||||
it('it should create a comment', function(done) {
|
||||
chai.request(app)
|
||||
.post('/api/v1/comments')
|
||||
.query({'body': 'Something body.', 'author_id': '123', 'asset_id': '1', 'parent_id': ''})
|
||||
.end(function(err, res){
|
||||
expect(res).to.have.status(201)
|
||||
done()
|
||||
})
|
||||
})
|
||||
expect(res).to.have.status(201);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
describe('Get /:comment_id', () => {
|
||||
const comments = [{
|
||||
@@ -54,40 +55,40 @@ describe('Get /:comment_id', () => {
|
||||
body: 'comment 10',
|
||||
asset_id: 'asset',
|
||||
author_id: '123'
|
||||
},{
|
||||
}, {
|
||||
id: 'def',
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456'
|
||||
},{
|
||||
}, {
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456'
|
||||
}]
|
||||
}];
|
||||
|
||||
const users = [{
|
||||
id: '123',
|
||||
display_name: 'John',
|
||||
},{
|
||||
}, {
|
||||
id: '456',
|
||||
display_name: 'Paul',
|
||||
}]
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
item_id: 'abc'
|
||||
},{
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: 'hij'
|
||||
}]
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Comment.create(comments).then(() => {
|
||||
return User.create(users)
|
||||
return User.create(users);
|
||||
}).then(() => {
|
||||
return Action.create(actions)
|
||||
})
|
||||
})
|
||||
return Action.create(actions);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the right comment for the comment_id', function(done){
|
||||
chai.request(app)
|
||||
@@ -96,11 +97,8 @@ describe('Get /:comment_id', () => {
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
if (err) return done(err);
|
||||
if (err) {return done(err);}
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,9 +2,11 @@ require('../../../utils/mongoose');
|
||||
|
||||
const app = require('../../../../app');
|
||||
const chai = require('chai');
|
||||
const chaiHttp = require('chai-http');
|
||||
chai.use(chaiHttp);
|
||||
var expect = chai.expect;
|
||||
const expect = chai.expect;
|
||||
|
||||
// Setup chai.
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const Action = require('../../../../models/action');
|
||||
const User = require('../../../../models/user');
|
||||
@@ -16,40 +18,40 @@ describe('api/stream: routes', () => {
|
||||
body: 'comment 10',
|
||||
asset_id: 'asset',
|
||||
author_id: '123'
|
||||
},{
|
||||
}, {
|
||||
id: 'def',
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456'
|
||||
},{
|
||||
}, {
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456'
|
||||
}]
|
||||
}];
|
||||
|
||||
const users = [{
|
||||
id: '123',
|
||||
display_name: 'John',
|
||||
},{
|
||||
}, {
|
||||
id: '456',
|
||||
display_name: 'Paul',
|
||||
}]
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
item_id: 'abc'
|
||||
},{
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: 'hij'
|
||||
}]
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Comment.create(comments).then(() => {
|
||||
return User.create(users)
|
||||
return User.create(users);
|
||||
}).then(() => {
|
||||
return Action.create(actions)
|
||||
})
|
||||
})
|
||||
return Action.create(actions);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a stream with comments, users and actions', function(done){
|
||||
chai.request(app)
|
||||
@@ -58,8 +60,8 @@ describe('api/stream: routes', () => {
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
if (err) return done(err);
|
||||
if (err) {return done(err);}
|
||||
done();
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var mongoose = require('mongoose');
|
||||
const mongoose = require('../../mongoose');
|
||||
|
||||
// Ensure the NODE_ENV is set to 'test',
|
||||
// this is helpful when you would like to change behavior when testing.
|
||||
@@ -6,18 +6,18 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
beforeEach(function (done) {
|
||||
function clearDB() {
|
||||
for (var i in mongoose.connection.collections) {
|
||||
for (let i in mongoose.connection.collections) {
|
||||
mongoose.connection.collections[i].remove(function() {});
|
||||
}
|
||||
return done();
|
||||
}
|
||||
|
||||
|
||||
if (mongoose.connection.readyState === 0) {
|
||||
mongoose.connect('coral-talk-test', function (err) {
|
||||
mongoose.on('open', function() {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
return clearDB();
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user