From d1214bc2d1543a135053a472c7c02422507abdda Mon Sep 17 00:00:00 2001 From: Mathew Henson Date: Mon, 17 Oct 2016 16:45:42 +0100 Subject: [PATCH] TSLint format changes [Completed]. Closes #30 --- main.ts | 4 +- src/controllers/comments-controller.ts | 28 +++++------ src/controllers/controller.ts | 4 +- src/controllers/emails-controller.ts | 15 +++--- src/controllers/page-renderer.ts | 20 ++++---- src/controllers/posts-controller.ts | 28 +++++------ src/definitions/custom/modepress.d.ts | 46 +++++++------------ src/definitions/generated/modepress.d.ts | 46 +++++++------------ src/definitions/required/express.d.ts | 12 ++--- src/models/model.ts | 17 ++++--- src/models/schema-items/schema-bool.ts | 3 +- src/models/schema-items/schema-date.ts | 3 +- src/models/schema-items/schema-foreign-key.ts | 11 ++--- src/models/schema-items/schema-html.ts | 7 ++- src/models/schema-items/schema-id-array.ts | 19 ++++---- src/models/schema-items/schema-id.ts | 7 ++- src/models/schema-items/schema-item.ts | 3 +- src/models/schema-items/schema-json.ts | 3 +- src/models/schema-items/schema-num-array.ts | 7 ++- src/models/schema-items/schema-number.ts | 5 +- src/models/schema-items/schema-text-array.ts | 7 ++- src/models/schema-items/schema-text.ts | 5 +- src/models/schema.ts | 16 +++---- src/path-handler.ts | 4 +- src/permission-controllers.ts | 12 ++--- src/server.ts | 8 ++-- src/startup.ts | 8 ++-- src/users-service.ts | 2 +- src/utils.ts | 2 +- test/tests/comments.js | 8 ++-- test/tests/posts.js | 2 +- 31 files changed, 160 insertions(+), 202 deletions(-) diff --git a/main.ts b/main.ts index e1c0f37c..aea0bebb 100644 --- a/main.ts +++ b/main.ts @@ -9,7 +9,7 @@ var numCPUs = os.cpus().length; // Check for the threads argument if ( args.numThreads ) { - if ( args.numThreads == "max" ) { + if ( args.numThreads === "max" ) { console.log( `Setting the number of clusters to ${numCPUs}` ); } else if ( isNaN( parseInt( args.numThreads ) ) ) { @@ -26,7 +26,7 @@ if ( args.numThreads ) { } // Run as a single cluster -if ( numCPUs == 1 ) { +if ( numCPUs === 1 ) { console.log( `Running as single cluster` ); require( "./src/startup.js" ); } diff --git a/src/controllers/comments-controller.ts b/src/controllers/comments-controller.ts index 503f2a36..d514b3ed 100644 --- a/src/controllers/comments-controller.ts +++ b/src/controllers/comments-controller.ts @@ -71,9 +71,9 @@ export default class CommentsController extends Controller { // Check for visibility if ( req.query.visibility ) { - if ( ( req.query.visibility ).toLowerCase() == 'all' ) + if ( ( req.query.visibility ).toLowerCase() === 'all' ) visibility = 'all'; - else if ( ( req.query.visibility ).toLowerCase() == 'private' ) + else if ( ( req.query.visibility ).toLowerCase() === 'private' ) visibility = 'private'; } else @@ -82,12 +82,12 @@ export default class CommentsController extends Controller { const users = UsersService.getSingleton(); // Only admins are allowed to see private comments - if ( !user || ( ( visibility == 'all' || visibility == 'private' ) && users.isAdmin( user ) == false ) ) + if ( !user || ( ( visibility === 'all' || visibility === 'private' ) && users.isAdmin( user ) === false ) ) visibility = 'public'; // Add the or conditions for visibility - if ( visibility != 'all' ) { - if ( visibility == 'public' ) + if ( visibility !== 'all' ) { + if ( visibility === 'public' ) ( findToken ).public = true; else ( findToken ).public = false; @@ -96,7 +96,7 @@ export default class CommentsController extends Controller { // Set the default sort order to ascending let sortOrder = -1; if ( req.query.sortOrder ) { - if ( ( req.query.sortOrder ).toLowerCase() == 'asc' ) + if ( ( req.query.sortOrder ).toLowerCase() === 'asc' ) sortOrder = 1; else sortOrder = -1; @@ -107,11 +107,11 @@ export default class CommentsController extends Controller { // Optionally sort by the last updated if ( req.query.sort ) { - if ( req.query.sort == 'updated' ) + if ( req.query.sort === 'updated' ) sort = { lastUpdated: sortOrder }; } - if ( findToken.$or.length == 0 ) + if ( findToken.$or.length === 0 ) delete findToken.$or; try { @@ -154,14 +154,14 @@ export default class CommentsController extends Controller { const instances = await comments.findInstances( findToken, [], 0, 1 ); - if ( instances.length == 0 ) + if ( instances.length === 0 ) throw new Error( 'Could not find comment' ); const users = UsersService.getSingleton(); const isPublic = await instances[ 0 ].schema.getByName( 'public' ) !.getValue() // Only admins are allowed to see private comments - if ( !isPublic && ( !user || users.isAdmin( user ) == false ) ) + if ( !isPublic && ( !user || users.isAdmin( user ) === false ) ) throw new Error( 'That comment is marked private' ); const jsons: Array> = []; @@ -200,13 +200,13 @@ export default class CommentsController extends Controller { const users = UsersService.getSingleton(); const instances = await comments.findInstances( findToken, [], 0, 1 ); - if ( instances.length == 0 ) + if ( instances.length === 0 ) throw new Error( 'Could not find a comment with that ID' ); else { const author = await instances[ 0 ].schema.getByName( 'author' ) !.getValue(); // Only admins are allowed to see private comments - if ( !user || ( !users.isAdmin( user ) && user.username != author ) ) + if ( !user || ( !users.isAdmin( user ) && user.username !== author ) ) throw new Error( 'You do not have permission' ); } @@ -237,13 +237,13 @@ export default class CommentsController extends Controller { const users = UsersService.getSingleton(); const instances = await comments.findInstances( findToken, [], 0, 1 ); - if ( instances.length == 0 ) + if ( instances.length === 0 ) throw new Error( 'Could not find comment with that id' ); else { const author = await instances[ 0 ].schema.getByName( 'author' ) !.getValue(); // Only admins are allowed to see private comments - if ( !user || ( !users.isAdmin( user ) && user.username != author ) ) + if ( !user || ( !users.isAdmin( user ) && user.username !== author ) ) throw new Error( 'You do not have permission' ); } diff --git a/src/controllers/controller.ts b/src/controllers/controller.ts index 7ae3dca8..f6df9d0e 100644 --- a/src/controllers/controller.ts +++ b/src/controllers/controller.ts @@ -15,7 +15,7 @@ export class Controller { let modelAlreadyAdded = false; for ( let i = 0, l = Controller._models.length; i < l; i++ ) - if ( Controller._models[ i ].collectionName == models[ ii ].collectionName ) { + if ( Controller._models[ i ].collectionName === models[ ii ].collectionName ) { modelAlreadyAdded = true; break; } @@ -54,7 +54,7 @@ export class Controller { getModel( collectionName: string ): Model | null { const models = Controller._models; for ( let i = 0, l = models.length; i < l; i++ ) - if ( models[ i ].collectionName == collectionName ) + if ( models[ i ].collectionName === collectionName ) return models[ i ]; return null; diff --git a/src/controllers/emails-controller.ts b/src/controllers/emails-controller.ts index 8442bd48..ea6ff4e7 100644 --- a/src/controllers/emails-controller.ts +++ b/src/controllers/emails-controller.ts @@ -38,14 +38,13 @@ export default class EmailsController extends controllerModule.Controller { // Set the content type res.setHeader( 'Content-Type', 'application/json' ); - const message: string = `Hello admin, - We have received a message from ${( req.body ).name}: - - ${( req.body ).message} - - Email: ${( req.body ).email} - Phone: ${( req.body ).phone} - Website: ${( req.body ).website}`; + const message: string = [ `Hello admin,`, + `We have received a message from ${( req.body ).name}:`, + `${( req.body ).message}`, + ``, + `Email: ${( req.body ).email}`, + `Phone: ${( req.body ).phone}`, + `Website: ${( req.body ).website}` ].join( '\r\n' ); UsersService.getSingleton().sendAdminEmail( message ).then( function( body ) { res.end( body ); diff --git a/src/controllers/page-renderer.ts b/src/controllers/page-renderer.ts index d2ba7cde..3cb1a602 100644 --- a/src/controllers/page-renderer.ts +++ b/src/controllers/page-renderer.ts @@ -227,7 +227,7 @@ export default class PageRenderer extends Controller { if ( Date.now() > expiration ) html = await this.renderPage( url ); - else if ( !html || html.trim() == '' ) + else if ( !html || html.trim() === '' ) html = await this.renderPage( url ); } else @@ -262,19 +262,19 @@ export default class PageRenderer extends Controller { let isRequestingPrerenderedPage = false; if ( !userAgent ) return false; - if ( req.method != 'GET' && req.method != 'HEAD' ) return false; + if ( req.method !== 'GET' && req.method !== 'HEAD' ) return false; - //if it contains _escaped_fragment_, show prerendered page + // if it contains _escaped_fragment_, show prerendered page const parsedQuery = url.parse( req.url, true ).query; if ( parsedQuery && parsedQuery[ '_escaped_fragment_' ] !== undefined ) isRequestingPrerenderedPage = true; - //if it is a bot...show prerendered page + // if it is a bot...show prerendered page if ( PageRenderer.crawlerUserAgents.some( function( crawlerUserAgent ) { return userAgent.toLowerCase().indexOf( crawlerUserAgent.toLowerCase() ) !== -1; }) ) isRequestingPrerenderedPage = true; - //if it is BufferBot...show prerendered page + // if it is BufferBot...show prerendered page if ( bufferAgent ) isRequestingPrerenderedPage = true; - //if it is a bot and is requesting a resource...dont prerender + // if it is a bot and is requesting a resource...dont prerender if ( PageRenderer.extensionsToIgnore.some( function( extension ) { return req.url.indexOf( extension ) !== -1; }) ) return false; return isRequestingPrerenderedPage; @@ -290,7 +290,7 @@ export default class PageRenderer extends Controller { try { const instances = await renders!.findInstances( { _id: new mongodb.ObjectID( req.params.id ) }); - if ( instances.length == 0 ) + if ( instances.length === 0 ) throw new Error( 'Could not find a render with that ID' ); let html: string = await instances[ 0 ].schema.getByName( 'html' ) !.getValue(); @@ -317,7 +317,7 @@ export default class PageRenderer extends Controller { try { const numRemoved = await renders!.deleteInstances( { _id: new mongodb.ObjectID( req.params.id ) }); - if ( numRemoved == 0 ) + if ( numRemoved === 0 ) throw new Error( 'Could not find a cache with that ID' ); okJson( { @@ -370,7 +370,7 @@ export default class PageRenderer extends Controller { // Set the default sort order to ascending let sortOrder = -1; if ( req.query.sortOrder ) { - if ( ( req.query.sortOrder ).toLowerCase() == 'asc' ) + if ( ( req.query.sortOrder ).toLowerCase() === 'asc' ) sortOrder = 1; else sortOrder = -1; @@ -390,7 +390,7 @@ export default class PageRenderer extends Controller { try { // First get the count count = await renders!.count( findToken ); - const instances = await renders!.findInstances( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent == false ? { html: 0 } : undefined ) ); + const instances = await renders!.findInstances( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent === false ? { html: 0 } : undefined ) ); const jsons: Array> = []; for ( let i = 0, l = instances.length; i < l; i++ ) diff --git a/src/controllers/posts-controller.ts b/src/controllers/posts-controller.ts index d327a7d7..b222f34c 100644 --- a/src/controllers/posts-controller.ts +++ b/src/controllers/posts-controller.ts @@ -73,9 +73,9 @@ export default class PostsController extends Controller { // Check for visibility if ( req.query.visibility ) { - if ( ( req.query.visibility ).toLowerCase() == 'all' ) + if ( ( req.query.visibility ).toLowerCase() === 'all' ) visibility = 'all'; - else if ( ( req.query.visibility ).toLowerCase() == 'private' ) + else if ( ( req.query.visibility ).toLowerCase() === 'private' ) visibility = 'private'; } else @@ -84,12 +84,12 @@ export default class PostsController extends Controller { const users = UsersService.getSingleton(); // Only admins are allowed to see private posts - if ( !user || ( ( visibility == 'all' || visibility == 'private' ) && users.isAdmin( user ) == false ) ) + if ( !user || ( ( visibility === 'all' || visibility === 'private' ) && users.isAdmin( user ) === false ) ) visibility = 'public'; // Add the or conditions for visibility - if ( visibility != 'all' ) { - if ( visibility == 'public' ) + if ( visibility !== 'all' ) { + if ( visibility === 'public' ) ( findToken ).public = true; else ( findToken ).public = false; @@ -124,7 +124,7 @@ export default class PostsController extends Controller { let sortOrder = -1; if ( req.query.sortOrder ) { - if ( ( req.query.sortOrder ).toLowerCase() == 'asc' ) + if ( ( req.query.sortOrder ).toLowerCase() === 'asc' ) sortOrder = 1; else sortOrder = -1; @@ -135,7 +135,7 @@ export default class PostsController extends Controller { // Optionally sort by the last updated if ( req.query.sort ) { - if ( req.query.sort == 'true' ) + if ( req.query.sort === 'true' ) sort = { lastUpdated: sortOrder }; } @@ -145,14 +145,14 @@ export default class PostsController extends Controller { // Stephen is lovely - if ( findToken.$or.length == 0 ) + if ( findToken.$or.length === 0 ) delete findToken.$or; try { // First get the count count = await posts!.count( findToken ); - const instances = await posts!.findInstances( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent == false ? { content: 0 } : undefined ) ); + const instances = await posts!.findInstances( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent === false ? { content: 0 } : undefined ) ); const jsons: Array> = []; for ( let i = 0, l = instances.length; i < l; i++ ) @@ -188,13 +188,13 @@ export default class PostsController extends Controller { const instances = await posts!.findInstances( findToken, [], 0, 1 ); - if ( instances.length == 0 ) + if ( instances.length === 0 ) throw new Error( 'Could not find post' ); const users = UsersService.getSingleton(); const isPublic = await instances[ 0 ].schema.getByName( 'public' ) !.getValue(); // Only admins are allowed to see private posts - if ( !isPublic && ( !user || users.isAdmin( user ) == false ) ) + if ( !isPublic && ( !user || users.isAdmin( user ) === false ) ) throw new Error( 'That post is marked private' ); const jsons: Array> = []; @@ -251,7 +251,7 @@ export default class PostsController extends Controller { // Attempt to delete the instances const numRemoved = await posts.deleteInstances( { _id: new mongodb.ObjectID( req.params.id ) }); - if ( numRemoved == 0 ) + if ( numRemoved === 0 ) throw new Error( 'Could not find a post with that ID' ); okJson( { @@ -273,7 +273,7 @@ export default class PostsController extends Controller { try { const numRemoved = await categories.deleteInstances( { _id: new mongodb.ObjectID( req.params.id ) }); - if ( numRemoved == 0 ) + if ( numRemoved === 0 ) return Promise.reject( new Error( 'Could not find a category with that ID' ) ); okJson( { @@ -299,7 +299,7 @@ export default class PostsController extends Controller { if ( instance.error ) throw new Error( instance.tokens[ 0 ].error ); - if ( instance.tokens.length == 0 ) + if ( instance.tokens.length === 0 ) throw new Error( 'Could not find post with that id' ); okJson( { diff --git a/src/definitions/custom/modepress.d.ts b/src/definitions/custom/modepress.d.ts index fafcc69f..688791e8 100644 --- a/src/definitions/custom/modepress.d.ts +++ b/src/definitions/custom/modepress.d.ts @@ -1,4 +1,4 @@ -declare module Modepress { +declare namespace Modepress { /* * Base interface for all models */ @@ -325,8 +325,7 @@ /** * A definition of each item in the model */ - class SchemaItem - { + class SchemaItem { public name: string; public value: T; @@ -494,8 +493,7 @@ * An instance of a model with its own unique schema and ID. The initial schema is a clone * the parent model's */ - class ModelInstance - { + class ModelInstance { public model: Model; public schema: Schema; public dbEntry: T; @@ -690,8 +688,7 @@ /** * A numeric schema item for use in Models */ - class SchemaNumber extends SchemaItem - { + class SchemaNumber extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -710,8 +707,7 @@ * Required keys will mean that the current document cannot exist if the target does not. Optional keys * will simply be nullified if the target no longer exists. */ - export class SchemaForeignKey extends SchemaItem - { + export class SchemaForeignKey extends SchemaItem { public targetCollection: string; public optionalKey: boolean; @@ -729,8 +725,7 @@ /** * A text scheme item for use in Models */ - class SchemaText extends SchemaItem - { + class SchemaText extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -744,8 +739,7 @@ /** * A n ID array scheme item for use in Models */ - export class SchemaIdArray extends SchemaItem> - { + export class SchemaIdArray extends SchemaItem> { /** * Creates a new schema item that holds an array of id items * @param name The name of this item @@ -759,8 +753,7 @@ /** * A number array scheme item for use in Models */ - export class SchemaNumArray extends SchemaItem> - { + export class SchemaNumArray extends SchemaItem> { /** * Creates a new schema item that holds an array of number items * @param name The name of this item @@ -778,8 +771,7 @@ /** * A text scheme item for use in Models */ - class SchemaTextArray extends SchemaItem> - { + class SchemaTextArray extends SchemaItem> { /** * Creates a new schema item that holds an array of text items * @param name The name of this item @@ -795,8 +787,7 @@ /** * A bool scheme item for use in Models */ - class SchemaBool extends SchemaItem - { + class SchemaBool extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -808,8 +799,7 @@ /** * A json scheme item for use in Models */ - class SchemaJSON extends SchemaItem - { + class SchemaJSON extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -821,8 +811,7 @@ /** * A date scheme item for use in Models */ - class SchemaDate extends SchemaItem - { + class SchemaDate extends SchemaItem { public useNow: boolean; /** @@ -837,8 +826,7 @@ /** * A mongodb ObjectID scheme item for use in Models */ - export class SchemaId extends SchemaItem - { + export class SchemaId extends SchemaItem { private _str: string; /** @@ -852,8 +840,7 @@ /** * An html scheme item for use in Models */ - export class SchemaHtml extends SchemaItem - { + export class SchemaHtml extends SchemaItem { /** * The default tags allowed * includes: h3, h4, h5, h6, blockquote, p, a, ul, ol, @@ -886,7 +873,7 @@ /** * A list of helper functions for creating schema items */ - export module SchemaFactory { + export namespace SchemaFactory { export var num: typeof SchemaNumber; export var text: typeof SchemaText; export var textArray: typeof SchemaTextArray; @@ -959,7 +946,6 @@ export function isValidID( str: string ): boolean; } -declare module 'modepress-api' -{ +declare module 'modepress-api' { export = Modepress; } \ No newline at end of file diff --git a/src/definitions/generated/modepress.d.ts b/src/definitions/generated/modepress.d.ts index 46920ad1..ae9a52fd 100644 --- a/src/definitions/generated/modepress.d.ts +++ b/src/definitions/generated/modepress.d.ts @@ -1,4 +1,4 @@ -declare module Modepress { +declare namespace Modepress { /* * Base interface for all models */ @@ -325,8 +325,7 @@ declare module Modepress { /** * A definition of each item in the model */ - class SchemaItem - { + class SchemaItem { public name: string; public value: T; @@ -494,8 +493,7 @@ declare module Modepress { * An instance of a model with its own unique schema and ID. The initial schema is a clone * the parent model's */ - class ModelInstance - { + class ModelInstance { public model: Model; public schema: Schema; public dbEntry: T; @@ -690,8 +688,7 @@ declare module Modepress { /** * A numeric schema item for use in Models */ - class SchemaNumber extends SchemaItem - { + class SchemaNumber extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -710,8 +707,7 @@ declare module Modepress { * Required keys will mean that the current document cannot exist if the target does not. Optional keys * will simply be nullified if the target no longer exists. */ - export class SchemaForeignKey extends SchemaItem - { + export class SchemaForeignKey extends SchemaItem { public targetCollection: string; public optionalKey: boolean; @@ -729,8 +725,7 @@ declare module Modepress { /** * A text scheme item for use in Models */ - class SchemaText extends SchemaItem - { + class SchemaText extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -744,8 +739,7 @@ declare module Modepress { /** * A n ID array scheme item for use in Models */ - export class SchemaIdArray extends SchemaItem> - { + export class SchemaIdArray extends SchemaItem> { /** * Creates a new schema item that holds an array of id items * @param name The name of this item @@ -759,8 +753,7 @@ declare module Modepress { /** * A number array scheme item for use in Models */ - export class SchemaNumArray extends SchemaItem> - { + export class SchemaNumArray extends SchemaItem> { /** * Creates a new schema item that holds an array of number items * @param name The name of this item @@ -778,8 +771,7 @@ declare module Modepress { /** * A text scheme item for use in Models */ - class SchemaTextArray extends SchemaItem> - { + class SchemaTextArray extends SchemaItem> { /** * Creates a new schema item that holds an array of text items * @param name The name of this item @@ -795,8 +787,7 @@ declare module Modepress { /** * A bool scheme item for use in Models */ - class SchemaBool extends SchemaItem - { + class SchemaBool extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -808,8 +799,7 @@ declare module Modepress { /** * A json scheme item for use in Models */ - class SchemaJSON extends SchemaItem - { + class SchemaJSON extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -821,8 +811,7 @@ declare module Modepress { /** * A date scheme item for use in Models */ - class SchemaDate extends SchemaItem - { + class SchemaDate extends SchemaItem { public useNow: boolean; /** @@ -837,8 +826,7 @@ declare module Modepress { /** * A mongodb ObjectID scheme item for use in Models */ - export class SchemaId extends SchemaItem - { + export class SchemaId extends SchemaItem { private _str: string; /** @@ -852,8 +840,7 @@ declare module Modepress { /** * An html scheme item for use in Models */ - export class SchemaHtml extends SchemaItem - { + export class SchemaHtml extends SchemaItem { /** * The default tags allowed * includes: h3, h4, h5, h6, blockquote, p, a, ul, ol, @@ -886,7 +873,7 @@ declare module Modepress { /** * A list of helper functions for creating schema items */ - export module SchemaFactory { + export namespace SchemaFactory { export var num: typeof SchemaNumber; export var text: typeof SchemaText; export var textArray: typeof SchemaTextArray; @@ -959,7 +946,6 @@ declare module Modepress { export function isValidID( str: string ): boolean; } -declare module 'modepress-api' -{ +declare module 'modepress-api' { export = Modepress; } \ No newline at end of file diff --git a/src/definitions/required/express.d.ts b/src/definitions/required/express.d.ts index 0321a2c9..ba558b5e 100644 --- a/src/definitions/required/express.d.ts +++ b/src/definitions/required/express.d.ts @@ -314,7 +314,7 @@ declare module "express" { /** * Short-hand for: * - * req.protocol == 'https' + * req.protocol === 'https' */ secure: boolean; @@ -434,22 +434,22 @@ declare module "express" { * @param code */ status(code: number): Response; - + /** * Set the response HTTP status code to `statusCode` and send its string representation as the response body. * @link http://expressjs.com/4x/api.html#res.sendStatus - * + * * Examples: - * + * * res.sendStatus(200); // equivalent to res.status(200).send('OK') * res.sendStatus(403); // equivalent to res.status(403).send('Forbidden') * res.sendStatus(404); // equivalent to res.status(404).send('Not Found') * res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error') - * + * * @param code */ sendStatus(code: number): Response; - + /** * Set Link header field with the given `links`. * diff --git a/src/models/model.ts b/src/models/model.ts index 77ad6467..80ef9e9d 100644 --- a/src/models/model.ts +++ b/src/models/model.ts @@ -16,8 +16,7 @@ export interface UpdateRequest { error: boolean; tokens: Array * An instance of a model with its own unique schema and ID. The initial schema is a clone * the parent model's */ -export class ModelInstance -{ +export class ModelInstance { public model: Model; public schema: Schema; public _id: mongodb.ObjectID; @@ -43,7 +42,7 @@ export class ModelInstance if ( items[ i ].getUnique() ) uniqueNames += items[ i ].name + ', '; - if ( uniqueNames != '' ) + if ( uniqueNames !== '' ) uniqueNames = uniqueNames.slice( 0, uniqueNames.length - 2 ); return uniqueNames; @@ -87,7 +86,7 @@ export abstract class Model { static registerModel( modelConstructor: any ): T { const models = Model._registeredModels; for ( const i in models ) - if ( modelConstructor == models[ i ].constructor ) + if ( modelConstructor === models[ i ].constructor ) return models[ i ]; return new modelConstructor(); @@ -143,7 +142,7 @@ export abstract class Model { if ( items[ i ].getIndexable() ) promises.push( this.createIndex( items[ i ].name, this.collection ) ); - if ( promises.length == 0 ) + if ( promises.length === 0 ) this._initialized = true; const models = await Promise.all( promises ); @@ -294,7 +293,7 @@ export abstract class Model { const instances = await this.findInstances( selector ); - if ( !instances || instances.length == 0 ) + if ( !instances || instances.length === 0 ) return 0; const promises: Array> = []; @@ -325,7 +324,7 @@ export abstract class Model { const instances = await this.findInstances( selector ); - if ( !instances || instances.length == 0 ) + if ( !instances || instances.length === 0 ) return toRet; for ( let i = 0, l = instances.length; i < l; i++ ) { @@ -383,7 +382,7 @@ export abstract class Model { for ( let i = 0, l = items.length; i < l; i++ ) { if ( items[ i ].getUnique() ) { hasUniqueField = true; - var searchField = {}; + const searchField = {}; searchField[ items[ i ].name ] = items[ i ].getDbValue(); searchToken.$or.push( searchField ); } @@ -395,7 +394,7 @@ export abstract class Model { return true; else { const result = await this.collection.count( searchToken ); - if ( result == 0 ) + if ( result === 0 ) return true; else return false; diff --git a/src/models/schema-items/schema-bool.ts b/src/models/schema-items/schema-bool.ts index de3d10af..267b7a9e 100644 --- a/src/models/schema-items/schema-bool.ts +++ b/src/models/schema-items/schema-bool.ts @@ -4,8 +4,7 @@ import { ISchemaOptions } from 'modepress-api'; /** * A bool scheme item for use in Models */ -export class SchemaBool extends SchemaItem -{ +export class SchemaBool extends SchemaItem { /** * Creates a new schema item * @param name The name of this item diff --git a/src/models/schema-items/schema-date.ts b/src/models/schema-items/schema-date.ts index f2d38625..a2784ecb 100644 --- a/src/models/schema-items/schema-date.ts +++ b/src/models/schema-items/schema-date.ts @@ -4,8 +4,7 @@ import { ISchemaOptions } from 'modepress-api'; /** * A date scheme item for use in Models */ -export class SchemaDate extends SchemaItem -{ +export class SchemaDate extends SchemaItem { public useNow: boolean; /** diff --git a/src/models/schema-items/schema-foreign-key.ts b/src/models/schema-items/schema-foreign-key.ts index cb993707..5fae3df5 100644 --- a/src/models/schema-items/schema-foreign-key.ts +++ b/src/models/schema-items/schema-foreign-key.ts @@ -11,8 +11,7 @@ import { SchemaIdArray } from './schema-id-array'; * Required keys will mean that the current document cannot exist if the target does not. Optional keys * will simply be nullified if the target no longer exists. */ -export class SchemaForeignKey extends SchemaItem -{ +export class SchemaForeignKey extends SchemaItem { public targetCollection: string; public optionalKey: boolean; public curLevel: number; @@ -55,10 +54,10 @@ export class SchemaForeignKey extends SchemaItemthis.value ) ) transformedValue = this.value = new ObjectID( this.value ); - else if ( ( this.value ).trim() != '' ) + else if ( ( this.value ).trim() !== '' ) throw new Error( `Please use a valid ID for '${this.name}'` ); else transformedValue = null; @@ -133,7 +132,7 @@ export class SchemaForeignKey extends SchemaItemthis.value; - if ( options.expandSchemaBlacklist && options.expandSchemaBlacklist.indexOf( this.name ) != -1 ) + if ( options.expandSchemaBlacklist && options.expandSchemaBlacklist.indexOf( this.name ) !== -1 ) return this.value; const model = Model.getByName( this.targetCollection ); diff --git a/src/models/schema-items/schema-html.ts b/src/models/schema-items/schema-html.ts index a2a703ba..55d22781 100644 --- a/src/models/schema-items/schema-html.ts +++ b/src/models/schema-items/schema-html.ts @@ -5,8 +5,7 @@ import sanitizeHtml = require( 'sanitize-html' ); /** * An html scheme item for use in Models */ -export class SchemaHtml extends SchemaItem -{ +export class SchemaHtml extends SchemaItem { /** * The default tags allowed * includes: h3, h4, h5, h6, blockquote, p, a, ul, ol, @@ -77,7 +76,7 @@ export class SchemaHtml extends SchemaItem const minCharacters = this.minCharacters; const transformedValue = this.value.trim(); - if ( transformedValue.length < minCharacters && minCharacters == 1 ) + if ( transformedValue.length < minCharacters && minCharacters === 1 ) return Promise.reject( new Error( `'${this.name}' cannot be empty` ) ); else if ( transformedValue.length > maxCharacters ) return Promise.reject( new Error( `The character length of '${this.name}' is too long, please keep it below ${maxCharacters}` ) ); @@ -85,7 +84,7 @@ export class SchemaHtml extends SchemaItem return Promise.reject( new Error( `The character length of '${this.name}' is too short, please keep it above ${minCharacters}` ) ); const sanitizedHTML = sanitizeHtml( this.value, { allowedAttributes: this.allowedAttributes, allowedTags: this.allowedTags }).trim(); - if ( this.errorBadHTML && transformedValue != sanitizedHTML ) + if ( this.errorBadHTML && transformedValue !== sanitizedHTML ) return Promise.reject( new Error( `'${this.name}' has html code that is not allowed` ) ); this.value = sanitizedHTML; diff --git a/src/models/schema-items/schema-id-array.ts b/src/models/schema-items/schema-id-array.ts index f8e05a3a..327d0e6a 100644 --- a/src/models/schema-items/schema-id-array.ts +++ b/src/models/schema-items/schema-id-array.ts @@ -13,8 +13,7 @@ import { Utils } from '../../utils'; * Currently we only support Id lookups that exist in the same model - i.e. if the ids are of objects * in different models we cannot get the object values. */ -export class SchemaIdArray extends SchemaItem> -{ +export class SchemaIdArray extends SchemaItem> { public targetCollection: string; public minItems: number; public maxItems: number; @@ -59,10 +58,10 @@ export class SchemaIdArray extends SchemaItemthis.value[ i ] ) ) transformedValue[ i ] = new ObjectID( this.value[ i ] ); - else if ( ( this.value[ i ] ).trim() != '' ) + else if ( ( this.value[ i ] ).trim() !== '' ) throw new Error( `Please use a valid ID for '${this.name}'` ); else throw new Error( `Please use a valid ID for '${this.name}'` ); @@ -70,7 +69,7 @@ export class SchemaIdArray extends SchemaItem this.maxItems ) throw new Error( `You have selected too many items for ${this.name}, please only use up to ${this.maxItems}` ); @@ -78,7 +77,7 @@ export class SchemaIdArray extends SchemaItem{ _id: arr[ i ] }); const results = await model.findInstances( query ); - if ( !results || results.length == 0 ) + if ( !results || results.length === 0 ) return; const pullQueries: Array> = []; @@ -180,7 +179,7 @@ export class SchemaIdArray extends SchemaItem -{ +export class SchemaId extends SchemaItem { /** * Creates a new schema item * @param name The name of this item @@ -33,10 +32,10 @@ export class SchemaId extends SchemaItem public validate(): Promise { let transformedValue: string | ObjectID | null = this.value; - if ( typeof this.value == 'string' ) { + if ( typeof this.value === 'string' ) { if ( Utils.isValidObjectID( this.value ) ) transformedValue = this.value = new ObjectID( this.value ); - else if ( ( this.value ).trim() != '' ) + else if ( ( this.value ).trim() !== '' ) return Promise.reject( new Error( `Please use a valid ID for '${this.name}'` ) ); else transformedValue = null; diff --git a/src/models/schema-items/schema-item.ts b/src/models/schema-items/schema-item.ts index f14f3ead..e73ac134 100644 --- a/src/models/schema-items/schema-item.ts +++ b/src/models/schema-items/schema-item.ts @@ -4,8 +4,7 @@ import { ModelInstance } from '../model'; /** * A definition of each item in the model */ -export class SchemaItem -{ +export class SchemaItem { public name: string; public value: T; private _sensitive: boolean; diff --git a/src/models/schema-items/schema-json.ts b/src/models/schema-items/schema-json.ts index 0a04306b..8b5bcfcd 100644 --- a/src/models/schema-items/schema-json.ts +++ b/src/models/schema-items/schema-json.ts @@ -5,8 +5,7 @@ import sanitizeHtml = require( 'sanitize-html' ); /** * A json scheme item for use in Models */ -export class SchemaJSON extends SchemaItem -{ +export class SchemaJSON extends SchemaItem { /** * Creates a new schema item * @param name The name of this item diff --git a/src/models/schema-items/schema-num-array.ts b/src/models/schema-items/schema-num-array.ts index 64cb5e87..7ef798ef 100644 --- a/src/models/schema-items/schema-num-array.ts +++ b/src/models/schema-items/schema-num-array.ts @@ -5,8 +5,7 @@ import { NumberType } from './schema-number'; /** * A number array scheme item for use in Models */ -export class SchemaNumArray extends SchemaItem> -{ +export class SchemaNumArray extends SchemaItem> { public minItems: number; public maxItems: number; public min: number; @@ -69,7 +68,7 @@ export class SchemaNumArray extends SchemaItem> const decimalPlaces = this.decimalPlaces; for ( let i = 0, l = transformedValue.length; i < l; i++ ) { - if ( type == NumberType.Integer ) + if ( type === NumberType.Integer ) temp = parseInt( transformedValue.toString() ); else temp = parseFloat(( parseFloat( transformedValue.toString() ).toFixed( decimalPlaces ) ) ); @@ -81,7 +80,7 @@ export class SchemaNumArray extends SchemaItem> } if ( transformedValue.length < this.minItems ) - return Promise.reject( new Error( `You must select at least ${this.minItems} item${( this.minItems == 1 ? '' : 's' )} for ${this.name}` ) ); + return Promise.reject( new Error( `You must select at least ${this.minItems} item${( this.minItems === 1 ? '' : 's' )} for ${this.name}` ) ); if ( transformedValue.length > this.maxItems ) return Promise.reject( new Error( `You have selected too many items for ${this.name}, please only use up to ${this.maxItems}` ) ); diff --git a/src/models/schema-items/schema-number.ts b/src/models/schema-items/schema-number.ts index 120e3700..018b3990 100644 --- a/src/models/schema-items/schema-number.ts +++ b/src/models/schema-items/schema-number.ts @@ -12,8 +12,7 @@ export enum NumberType { /** * A numeric schema item for use in Models */ -export class SchemaNumber extends SchemaItem -{ +export class SchemaNumber extends SchemaItem { public min: number; public max: number; public type: NumberType; @@ -63,7 +62,7 @@ export class SchemaNumber extends SchemaItem const decimalPlaces = this.decimalPlaces; let transformedValue: number = this.value; - if ( type == NumberType.Integer ) + if ( type === NumberType.Integer ) transformedValue = parseInt( transformedValue.toString() ); else transformedValue = parseFloat(( parseFloat( transformedValue.toString() ).toFixed( decimalPlaces ) ) ); diff --git a/src/models/schema-items/schema-text-array.ts b/src/models/schema-items/schema-text-array.ts index 28e38d5a..d2781448 100644 --- a/src/models/schema-items/schema-text-array.ts +++ b/src/models/schema-items/schema-text-array.ts @@ -5,8 +5,7 @@ import sanitizeHtml = require( 'sanitize-html' ); /** * A text scheme item for use in Models */ -export class SchemaTextArray extends SchemaItem> -{ +export class SchemaTextArray extends SchemaItem> { public minItems: number; public maxItems: number; public minCharacters: number; @@ -54,7 +53,7 @@ export class SchemaTextArray extends SchemaItem> for ( let i = 0, l = transformedValue.length; i < l; i++ ) { transformedValue[ i ] = sanitizeHtml( transformedValue[ i ].trim(), { allowedTags: [] }); - if ( transformedValue[ i ].trim() == '' ) + if ( transformedValue[ i ].trim() === '' ) toRemove.push( i ); } @@ -67,7 +66,7 @@ export class SchemaTextArray extends SchemaItem> if ( transformedValue.length < this.minItems ) - return Promise.reject( new Error( `You must select at least ${this.minItems} item${( this.minItems == 1 ? '' : 's' )} for ${this.name}` ) ); + return Promise.reject( new Error( `You must select at least ${this.minItems} item${( this.minItems === 1 ? '' : 's' )} for ${this.name}` ) ); if ( transformedValue.length > this.maxItems ) return Promise.reject( new Error( `You have selected too many items for ${this.name}, please only use up to ${this.maxItems}` ) ); diff --git a/src/models/schema-items/schema-text.ts b/src/models/schema-items/schema-text.ts index b14610a4..2b95a264 100644 --- a/src/models/schema-items/schema-text.ts +++ b/src/models/schema-items/schema-text.ts @@ -5,8 +5,7 @@ import sanitizeHtml = require( 'sanitize-html' ); /** * A text scheme item for use in Models */ -export class SchemaText extends SchemaItem -{ +export class SchemaText extends SchemaItem { public minCharacters: number; public maxCharacters: number; public htmlClean: boolean; @@ -57,7 +56,7 @@ export class SchemaText extends SchemaItem this.value = transformedValue; - if ( transformedValue.length < minCharacters && minCharacters == 1 ) + if ( transformedValue.length < minCharacters && minCharacters === 1 ) return Promise.reject( new Error( `${this.name} cannot be empty` ) ); if ( transformedValue.length > maxCharacters ) return Promise.reject( new Error( `The character length of ${this.name} is too long, please keep it below ${maxCharacters}` ) ); diff --git a/src/models/schema.ts b/src/models/schema.ts index 5709e32f..a12a7019 100644 --- a/src/models/schema.ts +++ b/src/models/schema.ts @@ -37,7 +37,7 @@ export class Schema { for ( const i in data ) { for ( let ii = 0; ii < l; ii++ ) - if ( items[ ii ].name == i ) + if ( items[ ii ].name === i ) items[ ii ].setValue( data[ i ] ); } } @@ -51,7 +51,7 @@ export class Schema { const items = this._items; for ( let i = 0, l = items.length; i < l; i++ ) - if ( items[ i ].name == name ) + if ( items[ i ].name === name ) items[ i ].setValue( val ); } @@ -93,7 +93,7 @@ export class Schema { for ( let i = 0, l = items.length; i < l; i++ ) { // If this data is sensitive and the request must be sanitized // then skip the item - if ( items[ i ].getSensitive() && options.verbose == false ) + if ( items[ i ].getSensitive() && options.verbose === false ) continue; itemsInUse.push( items[ i ] ); @@ -170,7 +170,7 @@ export class Schema { public getByName( val: string ): SchemaItem | null { const items = this._items; for ( let i = 0, l = items.length; i < l; i++ ) - if ( items[ i ].name == val ) + if ( items[ i ].name === val ) return items[ i ]; return null; @@ -181,11 +181,11 @@ export class Schema { * @param val The new item to add */ public add( val: SchemaItem ): SchemaItem { - if ( val.name == '_id' ) + if ( val.name === '_id' ) throw new Error( `You cannot use the schema item name _id as its a reserved keyword` ); - else if ( val.name == '_requiredDependencies' ) + else if ( val.name === '_requiredDependencies' ) throw new Error( `You cannot use the schema item name _requiredDependencies as its a reserved keyword` ); - else if ( val.name == '_optionalDependencies' ) + else if ( val.name === '_optionalDependencies' ) throw new Error( `You cannot use the schema item name _optionalDependencies as its a reserved keyword` ); else if ( this.getByName( val.name ) ) throw new Error( `An item with the name ${val.name} already exists.` ); @@ -205,7 +205,7 @@ export class Schema { name = ( >val ).name; for ( let i = 0, l = items.length; i < l; i++ ) - if ( items[ i ].name == name ) { + if ( items[ i ].name === name ) { items.splice( i, 1 ); return; } diff --git a/src/path-handler.ts b/src/path-handler.ts index dddff990..932923e9 100644 --- a/src/path-handler.ts +++ b/src/path-handler.ts @@ -35,7 +35,7 @@ export class PathHandler { const config = this._config; const path = this._path; - const requestIsSecure = ( ( req.connection ).encrypted || req.headers[ 'x-forwarded-proto' ] == 'https' ? true : false ); + const requestIsSecure = ( ( req.connection ).encrypted || req.headers[ 'x-forwarded-proto' ] === 'https' ? true : false ); const url = `${( requestIsSecure ? 'https' : 'http' )}://${config.host}`; const options: any = { usersURL: `${UsersService.usersURL}`, url: url }; @@ -50,7 +50,7 @@ export class PathHandler { // Give priority to template routes if ( fs.existsSync( path.index ) ) { - if ( path.index.indexOf( '.jade' ) != -1 ) + if ( path.index.indexOf( '.jade' ) !== -1 ) res.render( path.index, options ); else res.sendfile( path.index ); diff --git a/src/permission-controllers.ts b/src/permission-controllers.ts index db9ed5b8..d6fa4cfb 100644 --- a/src/permission-controllers.ts +++ b/src/permission-controllers.ts @@ -18,14 +18,14 @@ export function getUser( req: express.Request, res: express.Response, next: Func } else { ( req )._user = auth.user!; - ( req )._isAdmin = ( auth.user!.privileges == 1 || auth.user!.privileges == 2 ? true : false ); + ( req )._isAdmin = ( auth.user!.privileges === 1 || auth.user!.privileges === 2 ? true : false ); // Check if this must be cleaned or not let verbose = ( req.query.verbose ? true : false ); if ( verbose ) if ( !( req )._isAdmin ) - if ( req.params.user !== undefined && req.params.user != auth.user!.username ) + if ( req.params.user !== undefined && req.params.user !== auth.user!.username ) verbose = false; ( req )._verbose = verbose; @@ -106,7 +106,7 @@ export function isAdmin( req: express.Request, res: express.Response, next: Func throw new Error( 'You do not have permission' ); else { ( req )._user = auth.user!; - ( req )._isAdmin = ( auth.user!.privileges == 1 || auth.user!.privileges == 2 ? true : false ); + ( req )._isAdmin = ( auth.user!.privileges === 1 || auth.user!.privileges === 2 ? true : false ); ( req )._verbose = true; next(); } @@ -146,7 +146,7 @@ export async function canEdit( req: express.Request, res: express.Response, next throw new Error( 'You do not have permission' ); else { ( req )._user = auth.user!; - ( req )._isAdmin = ( auth.user!.privileges == 1 || auth.user!.privileges == 2 ? true : false ); + ( req )._isAdmin = ( auth.user!.privileges === 1 || auth.user!.privileges === 2 ? true : false ); ( req )._verbose = ( req.query.verbose ? true : false ); next(); return; @@ -171,13 +171,13 @@ export function isAuthenticated( req: express.Request, res: express.Response, ne throw new Error( auth.message ); ( req )._user = auth.user!; - ( req )._isAdmin = ( auth.user!.privileges == 1 || auth.user!.privileges == 2 ? true : false ); + ( req )._isAdmin = ( auth.user!.privileges === 1 || auth.user!.privileges === 2 ? true : false ); // Check if this must be cleaned or not let verbose = ( req.query.verbose ? true : false ); if ( verbose ) if ( !( req )._isAdmin ) - if ( req.params.user !== undefined && req.params.user != auth.user!.username ) + if ( req.params.user !== undefined && req.params.user !== auth.user!.username ) verbose = false; ( req )._verbose = verbose; diff --git a/src/server.ts b/src/server.ts index 5a401c58..6c16cc58 100644 --- a/src/server.ts +++ b/src/server.ts @@ -85,22 +85,22 @@ export class Server { // If we use SSL then start listening for that as well if ( server.ssl ) { - if ( server.sslIntermediate != '' && !fs.existsSync( server.sslIntermediate ) ) { + if ( server.sslIntermediate !== '' && !fs.existsSync( server.sslIntermediate ) ) { winston.error( `Could not find sslIntermediate: '${server.sslIntermediate}'`, { process: process.pid }); process.exit(); } - if ( server.sslCert != '' && !fs.existsSync( server.sslCert ) ) { + if ( server.sslCert !== '' && !fs.existsSync( server.sslCert ) ) { winston.error( `Could not find sslIntermediate: '${server.sslCert}'`, { process: process.pid }); process.exit(); } - if ( server.sslRoot != '' && !fs.existsSync( server.sslRoot ) ) { + if ( server.sslRoot !== '' && !fs.existsSync( server.sslRoot ) ) { winston.error( `Could not find sslIntermediate: '${server.sslRoot}'`, { process: process.pid }); process.exit(); } - if ( server.sslKey != '' && !fs.existsSync( server.sslKey ) ) { + if ( server.sslKey !== '' && !fs.existsSync( server.sslKey ) ) { winston.error( `Could not find sslIntermediate: '${server.sslKey}'`, { process: process.pid }); process.exit(); } diff --git a/src/startup.ts b/src/startup.ts index 9c56e243..291a4656 100644 --- a/src/startup.ts +++ b/src/startup.ts @@ -26,17 +26,17 @@ winston.remove( winston.transports.Console ); winston.add( winston.transports.Console, { level: 'debug', colorize: true }); // Saves logs to file -if ( args.logFile && args.logFile.trim() != '' ) +if ( args.logFile && args.logFile.trim() !== '' ) winston.add( winston.transports.File, { filename: args.logFile, maxsize: 50000000, maxFiles: 1, tailable: true }); // If no logging - remove all transports -if ( args.logging && args.logging.toLowerCase().trim() == 'false' ) { +if ( args.logging && args.logging.toLowerCase().trim() === 'false' ) { winston.clear(); } // Make sure the config path argument is there -if ( !args.config || args.config.trim() == '' ) { +if ( !args.config || args.config.trim() === '' ) { winston.error( 'No config file specified. Please start modepress with the config path in the argument list. Eg: node main.js --config="./config.js"', { process: process.pid }); process.exit(); } @@ -58,7 +58,7 @@ catch ( err ) { // Attempt to connect to Users -if ( config!.usersSocketURL != '' ) { +if ( config!.usersSocketURL !== '' ) { winston.info( `Attempting to connect to users socket at: '${config!.usersSocketURL}'`, { process: process.pid }); new EventManager( config! ).init().catch( function() { winston.error( `Could not connect to user socket even though it was specified at: '${config!.usersSocketURL}'`, { process: process.pid }); diff --git a/src/users-service.ts b/src/users-service.ts index 2c0e3f6f..1b43fe07 100644 --- a/src/users-service.ts +++ b/src/users-service.ts @@ -99,7 +99,7 @@ export class UsersService { */ hasPermission( user: UsersInterface.IUserEntry, level: number, existingUser?: string ): boolean { if ( existingUser !== undefined ) { - if ( ( user.email != existingUser && user.username != existingUser ) && user.privileges > level ) + if ( ( user.email !== existingUser && user.username !== existingUser ) && user.privileges > level ) return false; } else if ( user.privileges > level ) diff --git a/src/utils.ts b/src/utils.ts index 25171653..c2821801 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -11,7 +11,7 @@ export class Utils { // coerce to string so the function can be generically used to test both strings and native objectIds created by the driver str = str.trim() + ''; let len = str.length, valid = false; - if ( len == 12 || len == 24 ) + if ( len === 12 || len === 24 ) valid = /^[0-9a-fA-F]+$/.test( str ); return valid; diff --git a/test/tests/comments.js b/test/tests/comments.js index a0af5d73..e46efc9f 100644 --- a/test/tests/comments.js +++ b/test/tests/comments.js @@ -266,7 +266,7 @@ describe( 'Testing all comment related endpoints', function() { test.number( res.body.count ) test.array( res.body.data ).hasLength( 2 ) - test.bool( res.body.count == 2 ).isTrue() + test.bool( res.body.count === 2 ).isTrue() test.bool( res.body.error ).isFalse() done(); }); @@ -282,7 +282,7 @@ describe( 'Testing all comment related endpoints', function() { test.number( res.body.count ) test.array( res.body.data ).hasLength( 1 ) - test.bool( res.body.count == 2 ).isTrue() // Count is still 2 as + test.bool( res.body.count === 2 ).isTrue() // Count is still 2 as test.bool( res.body.error ).isFalse() done(); }); @@ -297,7 +297,7 @@ describe( 'Testing all comment related endpoints', function() { test.number( res.body.count ) test.array( res.body.data ).hasLength( 1 ) - test.bool( res.body.count == 1 ).isTrue() // Count is still 2 as + test.bool( res.body.count === 1 ).isTrue() // Count is still 2 as test.bool( res.body.error ).isFalse() done(); }); @@ -490,7 +490,7 @@ describe( 'Testing all comment related endpoints', function() { return done( err ); test.number( res.body.count ) - test.bool( numComments == res.body.count ).isTrue(); + test.bool( numComments === res.body.count ).isTrue(); test.bool( res.body.error ).isNotTrue() done(); }); diff --git a/test/tests/posts.js b/test/tests/posts.js index a5d1aefe..6147b430 100644 --- a/test/tests/posts.js +++ b/test/tests/posts.js @@ -502,7 +502,7 @@ describe( 'Testing all post related endpoints', function() { test.bool( res.body.error ).isNotTrue() .number( res.body.count ) - .bool( numPosts == res.body.count ).isTrue() + .bool( numPosts === res.body.count ).isTrue() done(); }); })