Skip to content

Commit

Permalink
Release/0.0.3 (#117)
Browse files Browse the repository at this point in the history
Co-authored-by: Jhonatan David <[email protected]>
Co-authored-by: MatheusDubin <[email protected]>
Co-authored-by: Lipe <[email protected]>
Co-authored-by: Gustavo Clemente <[email protected]>
Co-authored-by: kelvinsb <[email protected]>
Co-authored-by: Tatiane <[email protected]>
Co-authored-by: Sombrio <[email protected]>
Co-authored-by: AlbuquerqueRafael <[email protected]>
Co-authored-by: Arthur <[email protected]>
Co-authored-by: Giovanni Bassi <[email protected]>
Co-authored-by: LeoFC97 <[email protected]>
Co-authored-by: Rogério Piatek <[email protected]>
Co-authored-by: Anderson Rocha <[email protected]>
Co-authored-by: Pedro Perrone <[email protected]>
Co-authored-by: Kevin Eduard Piske <[email protected]>
Co-authored-by: Kevin Eduard Piske <[email protected]>
Co-authored-by: Wesley Araujo <[email protected]>
  • Loading branch information
18 people authored May 15, 2024
1 parent af6303a commit 8de74f3
Show file tree
Hide file tree
Showing 36 changed files with 465 additions and 64 deletions.
19 changes: 13 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ module.exports = {
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
plugins: ['@typescript-eslint/eslint-plugin', 'jest'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:jest/recommended',
],
root: true,
env: {
Expand All @@ -21,11 +22,17 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
"prettier/prettier": [
"error",
'jest/expect-expect': [
'warn',
{
"endOfLine": "auto"
}
]
assertFunctionNames: ['expect', 'request.**.expect'],
},
],
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
},
};
17 changes: 13 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: CI

on:
workflow_dispatch:
push:
branches:
- main
tags:
- '*'
pull_request:
branches:
- master
- main
- develop

jobs:
Expand All @@ -15,10 +21,10 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v4
# Setup node.js and cache
- name: "Setup node.js"
- name: 'Setup node.js'
uses: actions/setup-node@v4
with:
node-version: "18.x"
node-version: '18.x'
cache: 'npm'
cache-dependency-path: ./package-lock.json
# Install dependencies
Expand All @@ -29,4 +35,7 @@ jobs:
run: npm run lint:ci
# Build App
- name: Build App
run: npm run build
run: npm run build

- name: Test
run: npm test
20 changes: 20 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from 'jest';

const config: Config = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
moduleNameMapper: {
'^src/(.*)$': '<rootDir>/$1',
'^@/(.*)$': '<rootDir>/$1',
'^test/(.*)$': '<rootDir>/../$1',
},
testEnvironment: 'node',
};

export default config;
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 2 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:e2e": "jest --config ./test/jest.e2e.config.ts",
"migrations:run": "npx prisma migrate deploy",
"migrations:dev": "npx prisma migrate dev",
"docker:compose": "docker-compose -f docker-compose.dev.yml up"
Expand Down Expand Up @@ -53,6 +53,7 @@
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
Expand All @@ -64,22 +65,5 @@
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
14 changes: 14 additions & 0 deletions prisma/migrations/20240514211840_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- CreateTable
CREATE TABLE "partners" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"link" TEXT NOT NULL,
"iconName" TEXT NOT NULL DEFAULT 'Handshake',
"created_at" VARCHAR(32) NOT NULL,
"updated_at" VARCHAR(32),

CONSTRAINT "partners_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "partners_name_key" ON "partners"("name");
8 changes: 8 additions & 0 deletions prisma/migrations/20240515003750_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `iconName` on the `partners` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "partners" DROP COLUMN "iconName";
10 changes: 10 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,13 @@ model ShelterManagers {
@@id([shelterId, userId])
@@map("shelter_managers")
}

model Partners {
id String @id @default(uuid())
name String @unique
link String
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)
@@map("partners")
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SessionsModule } from './sessions/sessions.module';
import { SupplyCategoriesModule } from './supply-categories/supply-categories.module';
import { ShelterManagersModule } from './shelter-managers/shelter-managers.module';
import { ShelterSupplyModule } from './shelter-supply/shelter-supply.module';
import { PartnersModule } from './partners/partners.module';

@Module({
imports: [
Expand All @@ -22,6 +23,7 @@ import { ShelterSupplyModule } from './shelter-supply/shelter-supply.module';
SupplyCategoriesModule,
ShelterManagersModule,
ShelterSupplyModule,
PartnersModule,
],
controllers: [],
providers: [
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function bootstrap() {
.setTitle('SOS - Rio Grande do Sul')
.setDescription('...')
.setVersion('1.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
Expand Down
29 changes: 29 additions & 0 deletions src/partners/partners.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PartnersController } from './partners.controller';
import { PartnersService } from './partners.service';
import { PrismaService } from '../prisma/prisma.service';

describe('PartnersController', () => {
let controller: PartnersController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [PartnersController],
providers: [PartnersService],
})
.useMocker((token) => {
if (token === PrismaService) {
return {
supplyCategory: { findMany: jest.fn().mockResolvedValue(0) },
};
}
})
.compile();

controller = module.get<PartnersController>(PartnersController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
21 changes: 21 additions & 0 deletions src/partners/partners.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller, Get, HttpException, Logger } from '@nestjs/common';
import { PartnersService } from './partners.service';
import { ServerResponse } from '../utils';

@Controller('partners')
export class PartnersController {
private logger = new Logger(PartnersController.name);

constructor(private readonly partnersService: PartnersService) {}

@Get('')
async index() {
try {
const data = await this.partnersService.index();
return new ServerResponse(200, 'Successfully get partners', data);
} catch (err: any) {
this.logger.error(`Failed to get partners: ${err}`);
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400);
}
}
}
12 changes: 12 additions & 0 deletions src/partners/partners.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';

import { PartnersService } from './partners.service';
import { PartnersController } from './partners.controller';
import { PrismaModule } from '../prisma/prisma.module';

@Module({
imports: [PrismaModule],
providers: [PartnersService],
controllers: [PartnersController],
})
export class PartnersModule {}
28 changes: 28 additions & 0 deletions src/partners/partners.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Test, TestingModule } from '@nestjs/testing';

import { PartnersService } from './partners.service';
import { PrismaService } from '../prisma/prisma.service';

describe('PartnersService', () => {
let service: PartnersService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [PartnersService],
})
.useMocker((token) => {
if (token === PrismaService) {
return {
supplyCategory: { findMany: jest.fn().mockResolvedValue(0) },
};
}
})
.compile();

service = module.get<PartnersService>(PartnersService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
14 changes: 14 additions & 0 deletions src/partners/partners.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { PrismaService } from '../prisma/prisma.service';

@ApiTags('Parceiros')
@Injectable()
export class PartnersService {
constructor(private readonly prismaService: PrismaService) {}

async index() {
return await this.prismaService.partners.findMany({});
}
}
12 changes: 11 additions & 1 deletion src/sessions/sessions.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SessionsController } from './sessions.controller';
import { SessionsService } from './sessions.service';
import { PrismaService } from 'src/prisma/prisma.service';
import { JwtService } from '@nestjs/jwt';

describe('SessionsController', () => {
let controller: SessionsController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [SessionsController],
}).compile();
providers: [SessionsService, JwtService],
})
.useMocker((token) => {
if (token === PrismaService) {
return {};
}
})
.compile();

controller = module.get<SessionsController>(SessionsController);
});
Expand Down
12 changes: 10 additions & 2 deletions src/sessions/sessions.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SessionsService } from './sessions.service';
import { JwtService } from '@nestjs/jwt';
import { PrismaService } from 'src/prisma/prisma.service';

describe('SessionsService', () => {
let service: SessionsService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [SessionsService],
}).compile();
providers: [SessionsService, JwtService],
})
.useMocker((token) => {
if (token === PrismaService) {
return {};
}
})
.compile();

service = module.get<SessionsService>(SessionsService);
});
Expand Down
Loading

0 comments on commit 8de74f3

Please sign in to comment.