Skip to content

Commit

Permalink
Merge pull request #69 from RnDAO/github-actions
Browse files Browse the repository at this point in the history
GitHub actions
  • Loading branch information
Behzad-rabiei authored Jun 1, 2023
2 parents 2e31cc8 + f47ca62 commit 1c9e359
Show file tree
Hide file tree
Showing 38 changed files with 1,598 additions and 449 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.github/
coverage/
dist/
node_modules/

.env
34 changes: 15 additions & 19 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {}
}
"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"]
}
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: CI Pipeline

on: pull_request

jobs:
ci:
uses: TogetherCrew/operations/.github/workflows/ci.yml@main
secrets:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Publish

on:
release:
types: [published]

jobs:
ci:
uses: TogetherCrew/operations/.github/workflows/publish.ts.yml@main
secrets:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src/config/dev.env
src/config/test.env

/node_modules
/lib
/dist
/coverage
/.nyc_output
src/config/*.env
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
coverage
node_modules
2 changes: 1 addition & 1 deletion .prettierrc → .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:18-alpine AS base
WORKDIR /project
COPY . .
RUN npm ci

FROM base AS test
CMD [ "npx", "jest", "--coverage" ]

FROM base AS build
RUN npm run build

FROM build AS prod
RUN npm ci --omit=dev
CMD ["npm", "run", "start"]
42 changes: 31 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@

All interactions with DB

## Features

### Linter

The CI Pipeline uses [super-linter](https://github.com/super-linter/super-linter). You can run it locally with the following command:

```bash
docker run -e RUN_LOCAL=true -e TYPESCRIPT_DEFAULT_STYLE=prettier -e VALIDATE_DOCKERFILE_HADOLINT=false -v $(pwd):/tmp/lint github/super-linter:slim-latest
```

Note: We have disabled HADOLINT for now as we are getting an error: `qemu: uncaught target signal 11 (Segmentation fault) - core dumped`.
=======
[![Maintainability](https://api.codeclimate.com/v1/badges/52d516c2ad7c262adb37/maintainability)](https://codeclimate.com/github/RnDAO/tc-dbComm/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/52d516c2ad7c262adb37/test_coverage)](https://codeclimate.com/github/RnDAO/tc-dbComm/test_coverage)


## Schema for rawinfo

### Tests

The CI Pipeline uses the `test` target from the Dockerfile to run the tests. You can run it locally with the following command:

```bash
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: number,
author: Snowflake,
Expand All @@ -28,7 +52,7 @@ rawinfo {

### Schema for user

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

### Schema for heatmap

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

### Schema for guildMembers

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

### Schema for memberactivities

```
```ts
memberactivities {
date: Date,
all_active: Array<string>,
Expand All @@ -112,19 +134,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 @@ -136,7 +156,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();
});
});
});
});
10 changes: 10 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.9'

services:
app:
build:
context: .
target: test
dockerfile: Dockerfile
volumes:
- ./coverage:/project/coverage
Loading

0 comments on commit 1c9e359

Please sign in to comment.