Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Envs mocks #6

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: GitHub Pages

on:
push:
branches:
- main
pull_request:

jobs:
deploy:
runs-on: ubuntu-22.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- uses: nrwl/nx-set-shas@v3

- run: npm ci
- run: npx nx format:check
- run: npx nx affected -t lint --parallel=3
- run: npx nx affected -t test --parallel=3 --configuration=testing
- run: npx nx affected -t build --parallel=3 --configuration=development

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist/app
3 changes: 2 additions & 1 deletion account/data-access/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"tslib": "^2.3.0",
"@dev/account-domain": "*",
"@dev/shared-data-access": "*",
"@dev/shared-util-data": "*"
"@dev/shared-util-data": "*",
"rxjs": "^7.8.0"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
1 change: 1 addition & 0 deletions account/data-access/src/lib/infrastructure/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './user.service.impl'
export * from './user.service.mock'
16 changes: 16 additions & 0 deletions account/data-access/src/lib/infrastructure/user.service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {User, UserService} from '@dev/account-domain'
import {MockService} from '@dev/shared-data-access'
import {Observable, of} from 'rxjs'

export class UserServiceMock extends MockService<User> implements UserService {
create(value: Partial<User>): Observable<User> {
const entity = {
...value,
id: crypto.randomUUID(),
createdAt: new Date(),
updatedAt: new Date(),
} as User
this.collection.push(entity)
return of(entity)
}
}
2 changes: 1 addition & 1 deletion account/data-access/src/lib/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './user'
export * from './user'
25 changes: 20 additions & 5 deletions account/data-access/src/lib/providers/user.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import {UserService} from '@dev/account-domain'
import {UserServiceImpl} from '../infrastructure'
import {Http} from '@dev/shared-data-access'
import {User, UserService} from '@dev/account-domain'
import {UserServiceImpl, UserServiceMock} from '../infrastructure'
import {Http, provideServiceMock} from '@dev/shared-data-access'
import {UserFacade} from '../application'

export function provideUserService() {
export function provideUserService(api: string) {
return {
provide: UserService,
useFactory(http: Http) {
return new UserServiceImpl(http, '/api/account')
return new UserServiceImpl(http, api)
},
deps: [Http],
}
}

export function provideUserServiceMock(collection: User[] = []) {
return provideServiceMock(UserService, UserServiceMock, collection)
}

export function provideUserFacade() {
return {
provide: UserFacade,
deps: [UserService],
}
}

export function provideUser(production = false, api: string | User[] = []) {
const providers = []
providers.push(
production
? provideUserService(api as string)
: provideUserServiceMock(api as User[])
)
providers.push(provideUserFacade())
return providers
}
2 changes: 1 addition & 1 deletion account/data-source/src/lib/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './user';
export * from './user'
2 changes: 1 addition & 1 deletion account/domain/src/lib/entities/access-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export interface AccessCode {
id: string
code: string
email: string
}
}
2 changes: 1 addition & 1 deletion account/domain/src/lib/entities/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export interface Account {
id: string
email: string
phone?: number
}
}
2 changes: 0 additions & 2 deletions account/feature/src/lib/account-feature.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {ReactiveFormsModule} from '@angular/forms'
import {accountFeatureRoutes} from './account-feature.routes'
import {AccountFeatureContainer} from './account-feature.container'
import {CreateUserDialog, UpdateUserDialog} from './components'
import {provideUserFacade, provideUserService} from '@dev/account-data-access'
import {UiBaseModule} from '@dev/shared-ui-base'
import {UsersContainer} from './containers'

Expand All @@ -42,6 +41,5 @@ import {UsersContainer} from './containers'
CreateUserDialog,
UpdateUserDialog,
],
providers: [provideUserService(), provideUserFacade()],
})
export class AccountFeatureModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ <h2 mat-dialog-title>Criar usuário</h2>
<button type="button" mat-button mat-dialog-close>Cancelar</button>
<button mat-stroked-button color="primary">Enviar</button>
</footer>
</form>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ <h2 mat-dialog-title>Editar user</h2>
<button type="button" mat-button mat-dialog-close>Cancelar</button>
<button mat-stroked-button color="primary">Enviar</button>
</footer>
</form>
</form>
2 changes: 1 addition & 1 deletion account/feature/src/lib/containers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './users/users.container';
export * from './users/users.container'
30 changes: 23 additions & 7 deletions account/feature/src/lib/containers/users/users.container.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,28 @@
</dev-selection-menu>
</mat-card-content>

<table mat-table [dataSource]="dataSource" matSort matSortActive="createdAt" matSortDirection="desc">
<table
mat-table
[dataSource]="dataSource"
matSort
matSortActive="createdAt"
matSortDirection="desc"
>
<ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox (change)="$event ? toggleAllRows() : null" [checked]="selection.hasValue() && isAllSelected()"
[indeterminate]="selection.hasValue() && !isAllSelected()">
<mat-checkbox
(change)="$event ? toggleAllRows() : null"
[checked]="selection.hasValue() && isAllSelected()"
[indeterminate]="selection.hasValue() && !isAllSelected()"
>
</mat-checkbox>
</th>
<td mat-cell *matCellDef="let row">
<mat-checkbox (click)="$event.stopPropagation()" (change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)">
<mat-checkbox
(click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)"
>
</mat-checkbox>
</td>
</ng-container>
Expand Down Expand Up @@ -76,9 +88,13 @@
<tr mat-row *matRowDef="let row; columns: columns.value;"></tr>
</table>

<mat-paginator hidePageSize [length]="(meta$ | async)?.itemCount" [pageSize]="(meta$ | async)?.take"></mat-paginator>
<mat-paginator
hidePageSize
[length]="(meta$ | async)?.itemCount"
[pageSize]="(meta$ | async)?.take"
></mat-paginator>
</mat-card>

<button type="button" class="fixed b20 r20" mat-fab (click)="onCreate()">
<mat-icon>add</mat-icon>
</button>
</button>
2 changes: 1 addition & 1 deletion account/resource/src/lib/account-resource.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Controller,
NotFoundException,
} from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import {ApiTags} from '@nestjs/swagger'

@ApiTags('account')
@Controller('account')
Expand Down
3 changes: 3 additions & 0 deletions api/src/envs/env.prod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {DataConfig} from '@dev/shared-data-source'
import {Type} from '@dev/shared-util-data'
import {config} from 'dotenv'

config()

export const env = (...entities: Type<unknown>[]): DataConfig => ({
type: 'postgres',
Expand Down
15 changes: 3 additions & 12 deletions api/src/envs/env.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import {DataConfig} from '@dev/shared-data-source'
import {Type} from '@dev/shared-util-data'
import {config} from 'dotenv'

export const env = (entities: Type<unknown>[] = []): DataConfig => ({
type: 'postgres',
port: +(process.env.DB_PORT ?? '5432'),
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
synchronize: true,
logging: true,
entities,
})
config()

export const mdb = (entities: Type<unknown>[] = []): DataConfig => ({
export const env = (entities: Type<unknown>[] = []): DataConfig => ({
type: 'postgres',
port: +(process.env.DB_PORT ?? '5432'),
host: process.env.DB_HOST,
Expand Down
4 changes: 3 additions & 1 deletion api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {AppModule} from './app.module'
import {configSwagger} from './docs/config'

async function bootstrap() {
const app = await NestFactory.create(AppModule)
const app = await NestFactory.create(AppModule, {
cors: true,
})

const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
Expand Down
51 changes: 50 additions & 1 deletion app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,34 @@
"maximumError": "4kb"
}
],
"outputHashing": "all"
"outputHashing": "all",
"fileReplacements": [
{
"replace": "app/src/envs/env.ts",
"with": "app/src/envs/env.prod.ts"
}
]
},
"staging": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all",
"fileReplacements": [
{
"replace": "app/src/envs/env.ts",
"with": "app/src/envs/env.staging.ts"
}
]
},
"development": {
"buildOptimizer": false,
Expand All @@ -42,6 +69,20 @@
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
},
"testing": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true,
"fileReplacements": [
{
"replace": "app/src/envs/env.ts",
"with": "app/src/envs/env.testing.ts"
}
]
}
},
"defaultConfiguration": "production"
Expand Down Expand Up @@ -85,6 +126,14 @@
"ci": {
"ci": true,
"codeCoverage": true
},
"defaultConfiguration": {
"fileReplacements": [
{
"replace": "app/src/envs/env.ts",
"with": "app/src/envs/env.testing.ts"
}
]
}
}
}
Expand Down
Loading
Loading