Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cyri113 committed May 25, 2023
1 parent 5b4364f commit e97a52d
Show file tree
Hide file tree
Showing 24 changed files with 333 additions and 345 deletions.
30 changes: 15 additions & 15 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": ["standard-with-typescript", "prettier"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {},
"ignorePatterns": ["coverage", "dist"]
}
"env": {
"es2021": true,
"node": true
},
"extends": ["standard-with-typescript", "prettier"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {},
"ignorePatterns": ["coverage", "dist"]
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ jobs:
ci:
uses: TogetherCrew/operations/.github/workflows/ci.yml@main
secrets:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
}
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ docker compose -f docker-compose.test.yml up --exit-code-from app --build

Note: This will create a /coverage folder where you can review the coverage details.


## Schema for rawinfo

```
```ts
rawinfo {
type?: string,
author: string,
Expand All @@ -46,7 +45,7 @@ rawinfo {

### Schema for user

```
```ts
User {
discordId: Snowflake,
username?: string,
Expand All @@ -68,8 +67,7 @@ User {

### Schema for heatmap

```
```ts
HeatMap {
date?: string,(format: "YYYY-MM-DD")
thr_messages: Array<number>,
Expand All @@ -90,7 +88,7 @@ HeatMap {

### Schema for guildMembers

```
```ts
GuildMember {
discordId: Snowflake,
username: string,
Expand All @@ -105,8 +103,7 @@ GuildMember {

### Schema for memberactivities

```
```ts
memberactivities {
date: Date,
all_active: Array<string>,
Expand All @@ -130,19 +127,17 @@ memberactivities {

### Schema for channels

```
```ts
Channels {
channel: string,
channelId: Snowflake,
last_update: Date
}
```


### Schema for token

```
```ts
Token {
token: string,
user: Snowflake,
Expand All @@ -154,7 +149,7 @@ Token {

### Schema for guild

```
```ts
Guild {
guildId: Snowflake,
user: Snowflake,
Expand Down
8 changes: 4 additions & 4 deletions __tests__/unit/models/guildMember.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GuildMember } from '../../../src/models';
import { IGuildMember } from '../../../src/interfaces/GuildMember.interface';
import moment from "moment";
import moment from 'moment';

describe('Account model', () => {
describe('account validation', () => {
Expand All @@ -10,10 +10,10 @@ describe('Account model', () => {
discordId: '123',
username: 'Behzad#11',
roles: ['admin'],
joinedAt: moment("2022-02-01 08:30:26.127Z").toDate(),
avatar: "100",
joinedAt: moment('2022-02-01 08:30:26.127Z').toDate(),
avatar: '100',
isBot: true,
discriminator: 'str'
discriminator: 'str',
};
});
test('should correctly validate a valid guildMember data', async () => {
Expand Down
57 changes: 31 additions & 26 deletions __tests__/unit/models/heatMap.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import { HeatMap } from '../../../src/models';
import { IHeatMap } from '../../../src/interfaces/HeatMap.interface'
import { IHeatMap } from '../../../src/interfaces/HeatMap.interface';

describe('HeatMap model', () => {
describe('heatMap validation', () => {
let heatMap: IHeatMap;
beforeEach(() => {
heatMap = {
date: "2022-02-01",
thr_messages: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
lone_messages: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
replier: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
replied_per_acc: [{account: "Magic", count: 4}],
replied: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
mentioner: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
mentioner_per_acc: [{account: "Behzad", count: 4}, {account: "Magic", count: 2}],
mentioned: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
reacter: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
reacted_per_acc: [{account: "End", count: 2}, {account: "Magic", count: 2}],
reacted: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
channelId: "123123123123",
account_name: "MagicPalm"
}
});

test('should correctly validate a valid heatMap', async () => {
await expect(new HeatMap(heatMap).validate()).resolves.toBeUndefined();
});
describe('heatMap validation', () => {
let heatMap: IHeatMap;
beforeEach(() => {
heatMap = {
date: '2022-02-01',
thr_messages: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
lone_messages: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
replier: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
replied_per_acc: [{ account: 'Magic', count: 4 }],
replied: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
mentioner: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
mentioner_per_acc: [
{ account: 'Behzad', count: 4 },
{ account: 'Magic', count: 2 },
],
mentioned: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
reacter: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
reacted_per_acc: [
{ account: 'End', count: 2 },
{ account: 'Magic', count: 2 },
],
reacted: [0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 4, 3, 1, 2, 0, 1, 0, 1, 0, 2],
channelId: '123123123123',
account_name: 'MagicPalm',
};
});

test('should correctly validate a valid heatMap', async () => {
await expect(new HeatMap(heatMap).validate()).resolves.toBeUndefined();
});
});
});
});
41 changes: 20 additions & 21 deletions __tests__/unit/models/token.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { Token } from '../../../src/models';
import { IToken } from '../../../src/interfaces/Token.interface'
import moment from "moment";
import { IToken } from '../../../src/interfaces/Token.interface';
import moment from 'moment';

describe('Token model', () => {
describe('Token validation', () => {
let token: IToken;
beforeEach(() => {
token = {
user: "681946187490000906",
token: "716384",
type: "access",
expires: moment("2022-02-01 08:30:26.127Z").toDate()
};
});

test('should correctly validate a valid token', async () => {
await expect(new Token(token).validate()).resolves.toBeUndefined();
});
describe('Token validation', () => {
let token: IToken;
beforeEach(() => {
token = {
user: '1234',
token: '4321',
type: 'access',
expires: moment('2022-02-01 08:30:26.127Z').toDate(),
};
});

test('should throw a validation error if type is invalid', async () => {
token.type = 'invalidToken';
await expect(new Token(token).validate()).rejects.toThrow();
});
test('should correctly validate a valid token', async () => {
await expect(new Token(token).validate()).resolves.toBeUndefined();
});

test('should throw a validation error if type is invalid', async () => {
token.type = 'invalidToken';
await expect(new Token(token).validate()).rejects.toThrow();
});
});
});
});
32 changes: 16 additions & 16 deletions __tests__/unit/models/user.model.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { User } from '../../../src/models';
import { IUser } from '../../../src/interfaces/User.interface'
import { IUser } from '../../../src/interfaces/User.interface';

describe('User model', () => {
describe('User validation', () => {
let user: IUser;
beforeEach(() => {
user = {
discordId: "681946187490000906",
};
});
describe('User validation', () => {
let user: IUser;
beforeEach(() => {
user = {
discordId: '1234',
};
});

test('should correctly validate a valid user', async () => {
await expect(new User(user).validate()).resolves.toBeUndefined();
});
test('should correctly validate a valid user', async () => {
await expect(new User(user).validate()).resolves.toBeUndefined();
});

test('should throw a validation error if email is invalid', async () => {
user.email = 'invalidEmail';
await expect(new User(user).validate()).rejects.toThrow();
});
test('should throw a validation error if email is invalid', async () => {
user.email = 'invalidEmail';
await expect(new User(user).validate()).rejects.toThrow();
});
});
});
});
4 changes: 2 additions & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.9"
version: '3.9'

services:
app:
Expand All @@ -7,4 +7,4 @@ services:
target: test
dockerfile: Dockerfile
volumes:
- ./coverage:/project/coverage
- ./coverage:/project/coverage
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
};
preset: 'ts-jest',
testEnvironment: 'node',
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
"files": [
"lib/**/*"
]
}
}
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { User, Token, Guild, HeatMap, RawInfo, MemberActivity } from './models';
import { guildMemberSchema, guildSchema, heatMapSchema, MemberActivitySchema, rawInfoSchema, tokenSchema, userSchema } from './models/schemas';
import {
guildMemberSchema,
guildSchema,
heatMapSchema,
MemberActivitySchema,
rawInfoSchema,
tokenSchema,
userSchema,
} from './models/schemas';
import {
IDiscordGuild,
IDiscordOathBotCallback,
Expand All @@ -14,10 +22,7 @@ import { IGuildMember, IGuildMemberUpdateBody, GuildMemberModel } from './interf
import { IRawInfo, RawInfoModel } from './interfaces/RawInfo.interface';

import { IMemberActivity, MemberActivityModel } from './interfaces/MemberActivity.interface';
import {
databaseService,
heatmapService,
} from './service';
import { databaseService, heatmapService } from './service';

export {
User,
Expand Down Expand Up @@ -55,5 +60,5 @@ export {
MemberActivitySchema,
rawInfoSchema,
tokenSchema,
userSchema
userSchema,
};
Loading

0 comments on commit e97a52d

Please sign in to comment.