Skip to content

Commit

Permalink
feat: increase cov (#715)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Heroux <[email protected]>
  • Loading branch information
hxtree authored Nov 20, 2023
1 parent d60f568 commit e781764
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 14 deletions.
5 changes: 5 additions & 0 deletions common/scripts/dotenv/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ for file in $env_files; do
sed -i "s/MONGO_DATABASE_USER=/MONGO_DATABASE_USER=test-user/g" "${file%.dist}"
sed -i "s/MONGO_DATABASE_PASSWORD=/MONGO_DATABASE_PASSWORD=TpCg4mbwzk93B7tc/g" "${file%.dist}"

# uncomment to remove DB
# sed -i "s/MONGO_DATABASE_URI=//g" "${file%.dist}"
# sed -i "s/MONGO_DATABASE_USER=//g" "${file%.dist}"
# sed -i "s/MONGO_DATABASE_PASSWORD=//g" "${file%.dist}"

echo "Created and updated ${file%.dist}"
done

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import supertest from 'supertest';
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { MongooseModule } from '@cats-cradle/nestjs-modules';
import { FakerFactory } from '@cats-cradle/faker-factory';
import { v4 } from 'uuid';
Expand Down Expand Up @@ -36,6 +36,13 @@ describe('/character-sheets', () => {
}).compile();

const app: INestApplication = moduleRef.createNestApplication();
app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);

await app.init();

return { app, moduleRef } as const;
Expand Down
2 changes: 2 additions & 0 deletions services/design-system/src/Mui/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const Button = (props: ButtonProps) => {
...(props.selected && { backgroundColor: '#616366', color: '#FFF' }),
fontFamily: 'Helvetica, arial, sans-serif',
fontWeight: 'bold',
borderRadius: '36px',
padding: '15px 30px 10px 30px',
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { Meta } from '@storybook/react';
import { FontAwesomeIcon, Stack, Divider, Paper } from '../../../src';

export default {
title: 'Atoms/ColorPallette',
component: FontAwesomeIcon,
} as Meta<typeof FontAwesomeIcon>;

// TODO create a display of permitted colors
export const Default = () => (
<Stack
direction="row"
divider={<Divider orientation="vertical" flexItem />}
spacing={2}
>
<div style={{ background: '#000' }}></div>
</Stack>
);
10 changes: 7 additions & 3 deletions services/developer-portal/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# @cats-cradle/developer-portal

WIP Unstable
The Developer Portal service makes it easy to test multiple deployed service
endpoints. The service is not designed to work against local service endpoints
because that would involve starting n+1 services. It only works for deployed
services.

<https://redocly.com/customers/australia-post/>
## References

<https://redocly.com/docs/redoc/deployment/intro/#how-to-run-redoc-locally>
- [Redoc](https://redocly.com/customers/australia-post/)
- [Redoc Locally](https://redocly.com/docs/redoc/deployment/intro/#how-to-run-redoc-locally)
9 changes: 9 additions & 0 deletions services/developer-portal/src/get-service-specs.ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// TODO // Swagger -> get module from each service?

// involve spinning up many services.

// combine multiple swagger definitions, possibly by openapi-spec?

// Schema can be obtained from each main.ts

// should be a hard coded list of services supported
4 changes: 4 additions & 0 deletions services/developer-portal/src/get-services.ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const DeveloperServices = [ 'html-to-pdf', 'luck-by-dice',
'weather-control', 'email-service', 'character-sheet', ];

// TODO for each service get endpoint from SSM.
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ describe('/email-message', () => {
}).compile();

app = moduleRef.createNestApplication();
emailMessageRepository = moduleRef.get<EmailMessageRepository>(
EmailMessageRepository,
);

app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);

emailMessageRepository = moduleRef.get<EmailMessageRepository>(
EmailMessageRepository,
);

await app.init();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
VERSION_NEUTRAL,
Delete,
} from '@nestjs/common';
import { IsUuidV4Validator } from '@cats-cradle/validation-schemas';
import { CreateDto } from './create.dto';
import { InstanceRepository } from '../../models/instance.repository';
import { Instance } from '../../models/instance.schema';
Expand Down Expand Up @@ -42,9 +43,10 @@ export class InstanceController {
@Post()
async create(@Body() body: CreateDto) {
const instance = new Instance();
if (body.id !== undefined) {
if (IsUuidV4Validator(body.id)) {
instance._id = body.id;
}

instance.createdAt = new Date().toISOString();

// TODO publish event
Expand Down
31 changes: 29 additions & 2 deletions services/instances/src/module/instances/instance.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import supertest from 'supertest';
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import {
MongooseModule,
closeInMongodConnection,
Expand Down Expand Up @@ -34,6 +34,13 @@ describe('/instances', () => {
}).compile();

app = moduleRef.createNestApplication();
app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);

instanceRepository = moduleRef.get<InstanceRepository>(InstanceRepository);

await app.init();
Expand Down Expand Up @@ -103,7 +110,7 @@ describe('/instances', () => {
});

describe('POST /instances', () => {
it('should create an instance', async () => {
it('should create an instance when id not supplied', async () => {
const body = await FakerFactory.create<CreateDto>(
CreateDto,
{},
Expand All @@ -119,6 +126,26 @@ describe('/instances', () => {
id: body.id,
});

expect(response.body.id).toEqual(instance?._id);
expect(instance?.createdAt).toBeDefined();
});

it('should create an instance when id supplied', async () => {
const body = await FakerFactory.create<CreateDto>(
CreateDto,
{},
{ optionals: true, pojo: true },
);

const response = await supertest(app.getHttpServer())
.post('/instances')
.send(body)
.expect(201);

const instance = await instanceRepository.findOneOrFail({
id: body.id,
});

expect(response.body.id).toEqual(body.id);
expect(response.body.id).toEqual(instance?._id);
expect(instance?._id).toEqual(body.id);
Expand Down
2 changes: 1 addition & 1 deletion services/weather-control/openapi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"date": {
"type": "string",
"description": "Date",
"default": "2023-11-05T02:50:15.067Z"
"default": "2023-11-20T03:28:08.392Z"
},
"latitude": {
"type": "string",
Expand Down
10 changes: 8 additions & 2 deletions services/weather-control/src/module/weather/weather.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import supertest from 'supertest';
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { FakerFactory } from '@cats-cradle/faker-factory';
import { WeatherService } from './weather.service';
import { WeatherController } from './weather.controller';
Expand All @@ -21,7 +21,12 @@ describe('/weather', () => {
}).compile();

app = moduleRef.createNestApplication();

app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);
weatherService = moduleRef.get<WeatherService>(WeatherService);

await app.init();
Expand Down Expand Up @@ -92,6 +97,7 @@ describe('/weather', () => {
'should determine climate %i as %s',
async (latitude: number, climate: ClimateType) => {
const body = await FakerFactory.create<QueryDto>(QueryDto, {
date: new Date().toISOString(),
latitude: latitude.toString(),
});

Expand Down

0 comments on commit e781764

Please sign in to comment.