Skip to content

Commit 6c405bb

Browse files
committed
eslinting - backend
1 parent 654ac7b commit 6c405bb

28 files changed

+423
-416
lines changed

backend/.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
"padded-blocks": [0],
3939
"object-curly-newline": ["error", { "ImportDeclaration": "never" }],
4040
"no-plusplus": [0],
41+
"no-console": "warn",
4142
"arrow-parens": ["error", "as-needed"],
4243
"quotes": ["error", "single"],
4344
"@typescript-eslint/member-delimiter-style": ['error', {
@@ -57,7 +58,7 @@ module.exports = {
5758
"object-curly-newline": ["error", {
5859
"ObjectExpression": { "multiline": true, "minProperties": 4 },
5960
"ObjectPattern": { "multiline": true, "minProperties": 4 },
60-
"ImportDeclaration": { "multiline": true, "minProperties": 5 },
61+
"ImportDeclaration": { "multiline": true, "minProperties": 8 },
6162
"ExportDeclaration": { "multiline": true, "minProperties": 3 }
6263
}],
6364
"newline-per-chained-call": ["error", { "ignoreChainWithDepth": 3 }],

backend/package-lock.json

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"@sendgrid/mail": "^6.4.0",
2121
"body-parser": "^1.19.0",
22+
"bson": "^1.1.4",
2223
"cors": "^2.8.5",
2324
"deep-diff": "^1.0.2",
2425
"dotenv": "^16.0.3",

backend/src/controllers/tests/0-config-templates.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44

55
import {Response} from 'express';
66
import fs from 'fs';
7-
import {getTemplates} from '../config'
7+
import {getTemplates} from '../config';
88

99

1010
jest.mock('fs');
1111
const mockedFs: jest.Mocked<typeof fs> = jest.mocked(fs);
1212

1313
const req = {} as any;
14-
const res = {
15-
send: (x: string[]) => Promise.resolve(x)
16-
} as unknown as Response;
14+
const res = {send: (x: string[]) => Promise.resolve(x)} as unknown as Response;
1715

1816

1917
describe('config controller :: getTemplates', () => {
@@ -38,13 +36,13 @@ describe('config controller :: getTemplates', () => {
3836

3937
it.skip('returns all pug files in root folder /templates when ENABLE_ROOT_TEMPLATES', async () => {
4038

41-
})
39+
});
4240

43-
it.skip("doesn't return other file types", async () => {
41+
it.skip('doesnt return other file types', async () => {
4442

45-
})
43+
});
4644

4745
it.skip('strips off the .pug extension', async () => {
4846

49-
})
50-
})
47+
});
48+
});
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Exercises 0: Basic
22
// Jest Mocks for google-auth-library
33

4-
import { verify } from '../user'
5-
import { OAuth2Client } from 'google-auth-library';
6-
import config, { IConfig } from './../../config';
4+
import {OAuth2Client} from 'google-auth-library';
5+
import {verify} from '../user';
6+
import config, {IConfig} from '../../config';
77

88
let payload: any = null;
99

@@ -13,13 +13,13 @@ jest.mock('../../config', () => ({
1313
secret: 'string',
1414
domain: 'string',
1515
defaultRole: 'string',
16-
}
16+
},
1717
}));
1818
const mockedConfig: jest.Mocked<IConfig> = jest.mocked(config);
1919

2020
jest.mock('google-auth-library', () => {
2121
class FakeOAuth2Client {
22-
verifyIdToken() {
22+
verifyIdToken() { // eslint-disable-line class-methods-use-this
2323
return {getPayload: () => payload};
2424
}
2525
}
@@ -28,7 +28,7 @@ jest.mock('google-auth-library', () => {
2828
return {
2929
__esModule: true,
3030
...originalModule,
31-
OAuth2Client: FakeOAuth2Client
31+
OAuth2Client: FakeOAuth2Client,
3232
};
3333
});
3434

@@ -45,15 +45,20 @@ describe('user controller :: verify', () => {
4545
beforeEach(() => {
4646
// mockedAuthClient.mockClear();
4747
// authClientMock.mockClear();
48-
})
48+
});
4949

5050
it('returns "Invalid token" if it fails to get the payload', async () => {
5151
const result = await verify('token');
52-
expect(result).toBe('Invalid token')
53-
})
52+
expect(result).toBe('Invalid token');
53+
});
5454

5555
it('checks the audience & domain corresponds to ../config', async () => {
56-
payload = {email_verified: true, email: 'email', aud: 'id1', hd: 'itenium.be'}
56+
payload = {
57+
email_verified: true,
58+
email: 'email',
59+
aud: 'id1',
60+
hd: 'itenium.be',
61+
};
5762
jest.replaceProperty(config, 'security', {
5863
clientId: 'id1',
5964
secret: 'string',
@@ -62,18 +67,18 @@ describe('user controller :: verify', () => {
6267
});
6368
const result = await verify('token');
6469

65-
expect(result).toBeInstanceOf(Object)
66-
})
70+
expect(result).toBeInstanceOf(Object);
71+
});
6772

6873
it.skip('sets a default role if one has been set in config', () => {
6974

70-
})
75+
});
7176

7277
it.skip('automatically activates a user when a default role has been set in config', () => {
7378

74-
})
79+
});
7580

7681
it.skip('sets the audit property', () => {
7782

78-
})
79-
})
83+
});
84+
});

backend/src/controllers/tests/1-clients.test.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
// Test an async (req, res) Express function
33
// With manual Express mocks
44

5-
import { Request, Response } from 'express';
6-
import { ConfacRequest } from '../../models/technical';
7-
import { IAudit } from '../../models/common';
8-
import { IClient } from '../../models/clients'
9-
import { Jwt } from '../../models/technical'
10-
import { saveClient } from '../clients';
11-
import { SocketServerMock } from 'socket.io-mock-ts';
5+
import {Request, Response} from 'express';
6+
import {SocketServerMock} from 'socket.io-mock-ts'; // eslint-disable-line import/no-extraneous-dependencies
7+
import {ConfacRequest, Jwt} from '../../models/technical';
8+
import {IAudit} from '../../models/common';
9+
import {IClient} from '../../models/clients';
10+
import {saveClient} from '../clients';
1211

1312
const fakeUser: Jwt = {
1413
data: {
@@ -21,21 +20,17 @@ const fakeUser: Jwt = {
2120
},
2221
iat: 0,
2322
exp: 0,
24-
}
23+
};
2524

2625
const fakeClient: Partial<IClient> = {
2726
// _id: new ObjectID('xxx'),
2827
active: true,
2928
name: '',
3029
audit: {} as IAudit,
31-
}
30+
};
3231

3332

34-
const fakeDb = {
35-
collection: (colName: string) => ({
36-
insertOne: (client: any) => Promise.resolve({ops: [client]})
37-
})
38-
}
33+
const fakeDb = {collection: (colName: string) => ({insertOne: (client: any) => Promise.resolve({ops: [client]})})};
3934

4035

4136
describe('clients controller :: saveClient creation', () => {
@@ -47,22 +42,19 @@ describe('clients controller :: saveClient creation', () => {
4742
io: new SocketServerMock() as any,
4843
} as ConfacRequest;
4944

50-
const res = {
51-
send: (c: IClient) => Promise.resolve(c)
52-
} as unknown as Response;
53-
45+
const res = {send: (c: IClient) => Promise.resolve(c)} as unknown as Response;
5446
const result = await saveClient(req, res);
5547
const createdClient = result as unknown as IClient;
5648

5749
expect(createdClient.slug).toBe('company-x');
58-
})
50+
});
5951

6052

6153

6254
it.skip('sets the client.audit', () => {
6355
// TODO: Production is burning, implement this later!!
64-
})
65-
})
56+
});
57+
});
6658

6759

6860

@@ -71,10 +63,10 @@ describe('clients controller :: saveClient creation', () => {
7163
describe.skip('clients controller :: saveClient updating', () => {
7264
it('should update client.audit', () => {
7365

74-
})
66+
});
7567

7668
it('should insert full audit of the changes', () => {
7769
// TODO: Maybe this whole mongodb thing is a bit too much for our fakeDb...?
7870
// TODO: Or could test just the saveAudit function.
79-
})
80-
})
71+
});
72+
});

backend/src/controllers/tests/2-consultants.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1+
/* eslint-disable object-curly-newline */
12
// Exercises 2:
23
// In memory mongodb testing
34
// https://github.com/nodkz/mongodb-memory-server
45
// https://github.com/shelfio/jest-mongodb (not used here)
56

6-
import { Request, Response } from 'express';
7-
import { Db, MongoClient } from 'mongodb';
8-
import { ConfacRequest } from '../../models/technical';
9-
import { IAudit } from '../../models/common';
10-
import { Jwt } from '../../models/technical'
11-
import { saveConsultant } from '../consultants';
12-
import { IConsultant } from '../../models/consultants';
13-
// import { MongoMemoryServer } from 'mongodb-memory-server';
14-
import { SocketServerMock } from 'socket.io-mock-ts';
7+
import {Request, Response} from 'express';
8+
import {Db, MongoClient} from 'mongodb';
9+
// import {MongoMemoryServer} from 'mongodb-memory-server';
10+
import {SocketServerMock} from 'socket.io-mock-ts';// eslint-disable-line import/no-extraneous-dependencies
11+
import {IAudit} from '../../models/common';
12+
import {Jwt, ConfacRequest} from '../../models/technical';
13+
import {saveConsultant} from '../consultants';
14+
import {IConsultant} from '../../models/consultants';
1515

1616
const fakeUser: Jwt = {
17-
data: { _id: '_id', email: 'string', firstName: 'first', name: 'name', alias: 'alias', active: true },
17+
data: {_id: '_id', email: 'string', firstName: 'first', name: 'name', alias: 'alias', active: true},
1818
iat: 0, exp: 0,
19-
}
19+
};
2020

2121
const fakeConsultant: Partial<IConsultant> = {
2222
_id: undefined,
2323
firstName: '',
2424
name: '',
2525
audit: {} as IAudit,
26-
}
26+
};
2727

2828
const createFakeRequestAndResponse = (db: Db, consultant: Partial<IConsultant> | null = null) => {
2929
const req = {
@@ -34,11 +34,11 @@ const createFakeRequestAndResponse = (db: Db, consultant: Partial<IConsultant> |
3434
} as ConfacRequest;
3535

3636
const res = {
37-
send: (c: IConsultant) => Promise.resolve(c)
37+
send: (c: IConsultant) => Promise.resolve(c),
3838
} as unknown as Response;
3939

4040
return {req, res};
41-
}
41+
};
4242

4343
describe('consultants controller :: saveConsultant', () => {
4444
// let mongoServer: MongoMemoryServer;
@@ -61,7 +61,7 @@ describe('consultants controller :: saveConsultant', () => {
6161
beforeEach(async () => {
6262
// Clean the db for each run?
6363
// await db.collection('consultants').deleteMany({});
64-
})
64+
});
6565

6666
describe('creating a consultant', () => {
6767
// it('sets the consultant.slug', async () => {
@@ -91,21 +91,21 @@ describe('consultants controller :: saveConsultant', () => {
9191
it.skip('checks that the db record has expected name and firstName', async () => {
9292

9393
});
94-
})
94+
});
9595

9696
describe.skip('updating a consultant', () => {
9797
it('updates a consultant when it has an _id', () => {
9898

99-
})
99+
});
100100

101101
it('saves an audit record', () => {
102102

103-
})
103+
});
104104
});
105105

106106
// afterAll(async () => {
107107
// await connection.close();
108108
// await mongoServer.stop();
109109
// // await mongoServer.cleanup();
110110
// });
111-
})
111+
});

0 commit comments

Comments
 (0)