Skip to content

Commit

Permalink
feat: refactor faker tests (#488)
Browse files Browse the repository at this point in the history
Signed-off-by: hxtree <[email protected]>
  • Loading branch information
hxtree authored Nov 2, 2023
1 parent 87a7572 commit 8e2ee7a
Show file tree
Hide file tree
Showing 24 changed files with 127 additions and 27 deletions.
2 changes: 2 additions & 0 deletions libraries/faker-factory/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ module.exports = {
},
rules: {
'no-prototype-builtins': 'off',
'global-require': 'off',
'@typescript-eslint/no-var-requires': 'off',
},
};
12 changes: 12 additions & 0 deletions libraries/faker-factory/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@cats-cradle/faker-factory",
"entries": [
{
"version": "1.2.1",
"tag": "@cats-cradle/faker-factory_v1.2.1",
"date": "Thu, 02 Nov 2023 12:35:11 GMT",
"comments": {
"patch": [
{
"comment": "refactor tests"
}
]
}
},
{
"version": "1.2.0",
"tag": "@cats-cradle/faker-factory_v1.2.0",
Expand Down
9 changes: 8 additions & 1 deletion libraries/faker-factory/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log - @cats-cradle/faker-factory

This log was last generated on Wed, 01 Nov 2023 04:48:36 GMT and should not be manually modified.
This log was last generated on Thu, 02 Nov 2023 12:35:11 GMT and should not be manually modified.

## 1.2.1
Thu, 02 Nov 2023 12:35:11 GMT

### Patches

- refactor tests

## 1.2.0
Wed, 01 Nov 2023 04:48:36 GMT
Expand Down
2 changes: 1 addition & 1 deletion libraries/faker-factory/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cats-cradle/faker-factory",
"version": "1.2.0",
"version": "1.2.1",
"main": "./dist/index.js",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { FakerFactory } from '../faker-factory';
import { SampleClass, SampleChildClass, SampleEnum } from './sample-class';
import { FakerFactory } from './faker-factory';
import {
SampleClass,
SampleChildClass,
SampleEnum,
} from './__tests__/sample-class';

describe('FakerFactory', () => {
describe('create', () => {
Expand Down
2 changes: 1 addition & 1 deletion libraries/faker-factory/src/faker-factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ClassConstructor, plainToInstance } from 'class-transformer';
import { cloneDeep } from 'lodash';
import { Settings } from './settings';
import { Settings } from './settings.type';
import { generateFakeData } from './generate-fake-data';
import { getJsonSchemas } from './get-json-schemas';
import { toPojo } from './pojo';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateFakeData } from '../generate-fake-data';
import { SampleClass } from './sample-class';
import { getJsonSchemas } from '../get-json-schemas';
import { generateFakeData } from './generate-fake-data';
import { SampleClass } from './__tests__/sample-class';
import { getJsonSchemas } from './get-json-schemas';

describe('generateFakeData', () => {
it('should change to schema and back again correctly', async () => {
Expand Down
2 changes: 1 addition & 1 deletion libraries/faker-factory/src/generate-fake-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash';
import { JSONSchemaFaker } from 'json-schema-faker';
import currency from 'currency.js';
import { faker } from '@faker-js/faker';
import { Settings, defaultSettings } from './settings';
import { Settings, defaultSettings } from './settings.type';

/**
* Determines how JSONSchema is faked based on format, pattern, etc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// eslint-disable-next-line max-classes-per-file
import { Type } from 'class-transformer';
import { IsString, ValidateNested } from 'class-validator';
import { getJsonSchemas } from '../get-json-schemas';
import {
Type,
IsString,
ValidateNested,
} from '@cats-cradle/validation-schemas';
import { getJsonSchemas } from './get-json-schemas';

describe('getJsonSchemas', () => {
it.each([
Expand All @@ -11,7 +14,7 @@ describe('getJsonSchemas', () => {
])(
'should determine "%s" property to have JSONSchema format "%s"',
async (property: string, value: any) => {
const { SampleClass } = require('./sample-class');
const { SampleClass } = require('./__tests__/sample-class');
const schemas = getJsonSchemas();
expect(schemas.SampleClass.properties).toHaveProperty(
property,
Expand All @@ -29,7 +32,7 @@ describe('getJsonSchemas', () => {
])(
'should determine "%s" property to have JSONSchema pattern "%s"',
async (property: string, value: string) => {
const { SampleClass } = require('./sample-class');
const { SampleClass } = require('./__tests__/sample-class');
const schemas = getJsonSchemas();
expect(schemas.SampleClass.properties).toHaveProperty(property);
expect(schemas.SampleClass.properties).toHaveProperty(
Expand Down
5 changes: 3 additions & 2 deletions libraries/faker-factory/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './faker-factory';
export { Settings } from './settings.type';
export { FakerFactory } from './faker-factory';
export { toPojo, isPojo } from './pojo';
export { Settings } from './settings';
export { getJsonSchemas } from './get-json-schemas';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isPojo, toPojo } from '../pojo';
import { isPojo, toPojo } from './pojo';

class TestClass {
a: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Settings {
export type Settings = {
/**
* whether optional properties are faked:
* true for always generate
Expand All @@ -23,7 +23,7 @@ export interface Settings {
additionalProperties?: boolean | undefined;

ignoreProperties?: boolean | undefined;
}
};

export const defaultSettings: Settings = {
probability: 0.5,
Expand Down
12 changes: 12 additions & 0 deletions libraries/nestjs-modules/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@cats-cradle/nestjs-modules",
"entries": [
{
"version": "0.2.7",
"tag": "@cats-cradle/nestjs-modules_v0.2.7",
"date": "Thu, 02 Nov 2023 12:35:11 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/faker-factory\" to `1.2.1`"
}
]
}
},
{
"version": "0.2.6",
"tag": "@cats-cradle/nestjs-modules_v0.2.6",
Expand Down
7 changes: 6 additions & 1 deletion libraries/nestjs-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/nestjs-modules

This log was last generated on Wed, 01 Nov 2023 04:48:36 GMT and should not be manually modified.
This log was last generated on Thu, 02 Nov 2023 12:35:11 GMT and should not be manually modified.

## 0.2.7
Thu, 02 Nov 2023 12:35:11 GMT

_Version update only_

## 0.2.6
Wed, 01 Nov 2023 04:48:36 GMT
Expand Down
2 changes: 1 addition & 1 deletion libraries/nestjs-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cats-cradle/nestjs-modules",
"version": "0.2.6",
"version": "0.2.7",
"main": "./dist/index.js",
"repository": {
"type": "git",
Expand Down
15 changes: 15 additions & 0 deletions services/authentication-service/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{
"name": "@cats-cradle/authentication-service",
"entries": [
{
"version": "1.0.8",
"tag": "@cats-cradle/authentication-service_v1.0.8",
"date": "Thu, 02 Nov 2023 12:35:11 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/nestjs-modules\" to `0.2.7`"
},
{
"comment": "Updating dependency \"@cats-cradle/faker-factory\" to `1.2.1`"
}
]
}
},
{
"version": "1.0.7",
"tag": "@cats-cradle/authentication-service_v1.0.7",
Expand Down
7 changes: 6 additions & 1 deletion services/authentication-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/authentication-service

This log was last generated on Wed, 01 Nov 2023 04:48:36 GMT and should not be manually modified.
This log was last generated on Thu, 02 Nov 2023 12:35:11 GMT and should not be manually modified.

## 1.0.8
Thu, 02 Nov 2023 12:35:11 GMT

_Version update only_

## 1.0.7
Wed, 01 Nov 2023 04:48:36 GMT
Expand Down
2 changes: 1 addition & 1 deletion services/authentication-service/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cats-cradle/authentication-service",
"module": "commonjs",
"version": "1.0.7",
"version": "1.0.8",
"scripts": {
"dev": "nest start --debug --watch",
"build": "tsc",
Expand Down
12 changes: 12 additions & 0 deletions services/email-service/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@cats-cradle/email-service",
"entries": [
{
"version": "0.0.15",
"tag": "@cats-cradle/email-service_v0.0.15",
"date": "Thu, 02 Nov 2023 12:35:11 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/faker-factory\" to `1.2.1`"
}
]
}
},
{
"version": "0.0.14",
"tag": "@cats-cradle/email-service_v0.0.14",
Expand Down
7 changes: 6 additions & 1 deletion services/email-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/email-service

This log was last generated on Wed, 01 Nov 2023 04:48:36 GMT and should not be manually modified.
This log was last generated on Thu, 02 Nov 2023 12:35:11 GMT and should not be manually modified.

## 0.0.15
Thu, 02 Nov 2023 12:35:11 GMT

_Version update only_

## 0.0.14
Wed, 01 Nov 2023 04:48:36 GMT
Expand Down
2 changes: 1 addition & 1 deletion services/email-service/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cats-cradle/email-service",
"module": "commonjs",
"version": "0.0.14",
"version": "0.0.15",
"scripts": {
"dev": "nest start --debug --watch",
"build": "tsc",
Expand Down
12 changes: 12 additions & 0 deletions services/html-to-pdf/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@cats-cradle/html-to-pdf",
"entries": [
{
"version": "1.0.9",
"tag": "@cats-cradle/html-to-pdf_v1.0.9",
"date": "Thu, 02 Nov 2023 12:35:11 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@cats-cradle/faker-factory\" to `1.2.1`"
}
]
}
},
{
"version": "1.0.8",
"tag": "@cats-cradle/html-to-pdf_v1.0.8",
Expand Down
7 changes: 6 additions & 1 deletion services/html-to-pdf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @cats-cradle/html-to-pdf

This log was last generated on Wed, 01 Nov 2023 04:48:36 GMT and should not be manually modified.
This log was last generated on Thu, 02 Nov 2023 12:35:11 GMT and should not be manually modified.

## 1.0.9
Thu, 02 Nov 2023 12:35:11 GMT

_Version update only_

## 1.0.8
Wed, 01 Nov 2023 04:48:36 GMT
Expand Down
2 changes: 1 addition & 1 deletion services/html-to-pdf/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cats-cradle/html-to-pdf",
"module": "commonjs",
"version": "1.0.8",
"version": "1.0.9",
"license": "MIT",
"description": "Your Go-To Solution for PDF Generation from HTML.",
"bugs": {
Expand Down

0 comments on commit 8e2ee7a

Please sign in to comment.