Skip to content

Commit

Permalink
chore: add prettier and format all
Browse files Browse the repository at this point in the history
  • Loading branch information
ike18t committed May 21, 2024
1 parent fb5653d commit 0d9e8fd
Show file tree
Hide file tree
Showing 18 changed files with 361 additions and 213 deletions.
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "none"
}
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
pluginJs.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintConfigPrettier,
{ ignores: ['jest.config.ts', 'eslint.config.mjs'] },
{
languageOptions: {
Expand Down
9 changes: 2 additions & 7 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
module.exports = {
moduleFileExtensions: [
'ts',
'js',
],
moduleFileExtensions: ['ts', 'js'],
restoreMocks: true,
roots: [
'<rootDir>/lib'
],
roots: ['<rootDir>/lib'],
setupFiles: [],
testRegex: '(.*\\.spec)\\.ts$',
transform: {
Expand Down
24 changes: 19 additions & 5 deletions lib/builders/match_builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,33 @@ describe('MatchBuilder', () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToJson('foo', true);

const expectedJSON = JSON.stringify({ equalToJson: 'foo', ignoreArrayOrder: true });
const expectedJSON = JSON.stringify({
equalToJson: 'foo',
ignoreArrayOrder: true
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});

it('json stringifies to { equalToJson: value, ignoreExtraElements: true }', () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToJson('foo', false, true);

const expectedJSON = JSON.stringify({ equalToJson: 'foo', ignoreExtraElements: true });
const expectedJSON = JSON.stringify({
equalToJson: 'foo',
ignoreExtraElements: true
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});

it('json stringifies to { equalToJson: value, ignoreArrayOrder: true, ignoreExtraElements: true }', () => {
const builder = new MatchBuilder(new RequestBuilderImpl());
builder.equalToJson('foo', true, true);

const expectedJSON = JSON.stringify({ equalToJson: 'foo', ignoreArrayOrder: true, ignoreExtraElements: true });
const expectedJSON = JSON.stringify({
equalToJson: 'foo',
ignoreArrayOrder: true,
ignoreExtraElements: true
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});

Expand All @@ -94,7 +104,9 @@ describe('MatchBuilder', () => {
const builder = new MatchBuilder(requestBuilder);
builder.equalToJson({ foo: 'bar' });

const expectedJSON = JSON.stringify({ equalToJson: JSON.stringify({ foo: 'bar' }) });
const expectedJSON = JSON.stringify({
equalToJson: JSON.stringify({ foo: 'bar' })
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});

Expand All @@ -103,7 +115,9 @@ describe('MatchBuilder', () => {
const builder = new MatchBuilder(requestBuilder);
builder.equalToJson(JSON.stringify({ foo: 'bar' }));

const expectedJSON = JSON.stringify({ equalToJson: JSON.stringify({ foo: 'bar' }) });
const expectedJSON = JSON.stringify({
equalToJson: JSON.stringify({ foo: 'bar' })
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
});
Expand Down
6 changes: 5 additions & 1 deletion lib/builders/match_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export class MatchBuilder {
return this.requestBuilder;
}

public equalToJson(json: object | string, ignoreArrayOrder: boolean = false, ignoreExtraElements: boolean = false) {
public equalToJson(
json: object | string,
ignoreArrayOrder: boolean = false,
ignoreExtraElements: boolean = false
) {
this.matchType = 'equalToJson';
if (typeof json === 'object') {
json = JSON.stringify(json); // tslint:disable-line
Expand Down
16 changes: 12 additions & 4 deletions lib/builders/request_builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ describe('RequestBuilderImpl', () => {
it('should json stringify to { basicAuth: { username: value, password: value } }', () => {
const builder = new RequestBuilderImpl();
builder.withBasicAuth('ike', '1234');
const expectedJSON = JSON.stringify({ basicAuthCredentials: { username: 'ike', password: '1234' } });
const expectedJSON = JSON.stringify({
basicAuthCredentials: { username: 'ike', password: '1234' }
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});

Expand All @@ -130,23 +132,29 @@ describe('RequestBuilderImpl', () => {
describe('withCookie', () => {
it('should json stringify to { cookies: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }', () => {
const builder = new RequestBuilderImpl().withCookie('ike').absent;
const expectedJSON = JSON.stringify({ cookies: { ike: { absent: true } } });
const expectedJSON = JSON.stringify({
cookies: { ike: { absent: true } }
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
});

describe('withHeader', () => {
it('should json stringify to { headers: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }', () => {
const builder = new RequestBuilderImpl().withHeader('ike').absent;
const expectedJSON = JSON.stringify({ headers: { ike: { absent: true } } });
const expectedJSON = JSON.stringify({
headers: { ike: { absent: true } }
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
});

describe('withQueryParam', () => {
it('should json stringify to { queryParameters: { key: {{ JSON GENERATED BY MATCH BUILDER }} } }', () => {
const builder = new RequestBuilderImpl().withQueryParam('ike').absent;
const expectedJSON = JSON.stringify({ queryParameters: { ike: { absent: true } } });
const expectedJSON = JSON.stringify({
queryParameters: { ike: { absent: true } }
});
expect(JSON.stringify(builder)).toEqual(expectedJSON);
});
});
Expand Down
5 changes: 4 additions & 1 deletion lib/builders/request_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export class RequestBuilderImpl implements RequestBuilder {
return this;
}

public toJSON: () => RequestJSON = () => ({ ...this.request, ...this.urlMatchBuilder.toJSON() });
public toJSON: () => RequestJSON = () => ({
...this.request,
...this.urlMatchBuilder.toJSON()
});

public withBasicAuth(username: string, password: string): RequestBuilder {
this.request.basicAuthCredentials = { username, password };
Expand Down
16 changes: 8 additions & 8 deletions lib/builders/url_match_builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { UrlMatchBuilder } from './url_match_builder';

describe('UrlMatchBuilder', () => {
describe('constructed with path = true', () => {
describe('equalTo', () => {
it('json stringifies to { urlPath: value }', () => {
describe('equalTo', () => {
it('json stringifies to { urlPath: value }', () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), true);
builder.equalTo('/some/path');

Expand All @@ -19,8 +19,8 @@ describe('UrlMatchBuilder', () => {
});
});

describe('matching', () => {
it('json stringifies to { urlPattern: value }', () => {
describe('matching', () => {
it('json stringifies to { urlPattern: value }', () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), true);
builder.matching('/some/path');

Expand All @@ -37,8 +37,8 @@ describe('UrlMatchBuilder', () => {
});

describe('constructed with path = false', () => {
describe('equalTo', () => {
it('json stringifies to { url: value }', () => {
describe('equalTo', () => {
it('json stringifies to { url: value }', () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), false);
builder.equalTo('/some/path');

Expand All @@ -47,8 +47,8 @@ describe('UrlMatchBuilder', () => {
});
});

describe('matching', () => {
it('json stringifies to { urlPattern: value }', () => {
describe('matching', () => {
it('json stringifies to { urlPattern: value }', () => {
const builder = new UrlMatchBuilder(new RequestBuilderImpl(), false);
builder.matching('/some/path');

Expand Down
6 changes: 4 additions & 2 deletions lib/builders/url_match_builder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { RequestBuilder } from './request_builder';

export class UrlMatchBuilder {

private jsonObject = {};

constructor(private readonly requestBuilder: RequestBuilder, private readonly path: boolean = false) {}
constructor(
private readonly requestBuilder: RequestBuilder,
private readonly path: boolean = false
) {}

public equalTo(url: string): RequestBuilder {
const urlType = this.path ? 'urlPath' : 'url';
Expand Down
20 changes: 15 additions & 5 deletions lib/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@ import { Configuration } from './configuration';

describe('Configuration', () => {
describe('createGlobalMapping', () => {
beforeEach(() => { Configuration.reset(); });
afterEach(() => { Configuration.reset(); });
beforeEach(() => {
Configuration.reset();
});
afterEach(() => {
Configuration.reset();
});

it('should set the request builder on configuration', () => {
Configuration.createGlobalMapping((requestBuilder) => {
requestBuilder.withHeader('foo').equalTo('bar');
});
const expectedJSON = JSON.stringify({ headers: { foo: { equalTo: 'bar' } } });
expect(JSON.stringify(Configuration.requestBuilder)).toEqual(expectedJSON);
const expectedJSON = JSON.stringify({
headers: { foo: { equalTo: 'bar' } }
});
expect(JSON.stringify(Configuration.requestBuilder)).toEqual(
expectedJSON
);
});

it('should set the response builder on configuration', () => {
Configuration.createGlobalMapping((_, responseBuilder) => {
responseBuilder.withDelay(500);
});
const expectedJSON = JSON.stringify({ fixedDelayMilliseconds: 500 });
expect(JSON.stringify(Configuration.responseBuilder)).toEqual(expectedJSON);
expect(JSON.stringify(Configuration.responseBuilder)).toEqual(
expectedJSON
);
});
});
});
6 changes: 4 additions & 2 deletions lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class Configuration {
Configuration.responseBuilderImpl = new ResponseBuilderImpl();
}

private static requestBuilderImpl: RequestBuilderImpl = new RequestBuilderImpl();
private static responseBuilderImpl: ResponseBuilderImpl = new ResponseBuilderImpl();
private static requestBuilderImpl: RequestBuilderImpl =
new RequestBuilderImpl();
private static responseBuilderImpl: ResponseBuilderImpl =
new ResponseBuilderImpl();
}
Loading

0 comments on commit 0d9e8fd

Please sign in to comment.