Skip to content

Commit 9c2404a

Browse files
Kamil GajowySikora00
authored andcommitted
chore(mocks-in-e2e0tests): apply prettier & minor changes
1 parent bcc76fd commit 9c2404a

11 files changed

Lines changed: 136 additions & 152 deletions

File tree

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import {Module} from '@nestjs/common';
2-
import {OrdersModule} from "./orders";
1+
import { Module } from '@nestjs/common';
2+
import { OrdersModule } from './orders';
33

44
@Module({
5-
imports: [OrdersModule],
5+
imports: [OrdersModule],
66
})
7-
export class AppModule {
8-
}
7+
export class AppModule {}
Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
import {Body, Controller, Get, Param, Post} from "@nestjs/common";
2-
import {ApiNoContentResponse} from "@nestjs/swagger";
3-
import {OrderDto} from "./order.dto";
4-
import {Service, PaymentStatus} from "./service";
1+
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
2+
import { ApiNoContentResponse } from '@nestjs/swagger';
3+
import { OrderDto } from './order.dto';
4+
import { Service, PaymentStatus } from './service';
55

66
@Controller()
77
export class OrdersController {
8+
constructor(private readonly gateway: Service) {}
89

9-
constructor(
10-
private readonly gateway: Service
11-
) {
12-
}
10+
@ApiNoContentResponse()
11+
@Post()
12+
async createOrder(@Body() body: OrderDto): Promise<void> {
13+
return this.gateway.createOrder(body.uuid);
14+
}
1315

14-
@ApiNoContentResponse()
15-
@Post()
16-
async createOrder(
17-
@Body() body: OrderDto
18-
): Promise<void> {
19-
return this.gateway.createOrder(body.uuid);
20-
}
21-
22-
@Get(`:id`)
23-
async getOrderStatus(
24-
@Param("id") orderId: string
25-
): Promise<{ status: PaymentStatus }> {
26-
return {
27-
status: await this.gateway.getOrderStatus(orderId)
28-
};
29-
}
30-
}
16+
@Get(`:id`)
17+
async getOrderStatus(
18+
@Param('id') orderId: string,
19+
): Promise<{ status: PaymentStatus }> {
20+
return {
21+
status: await this.gateway.getOrderStatus(orderId),
22+
};
23+
}
24+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {OrdersModule} from "./module";
1+
export { OrdersModule } from './module';
22

3-
export {PaymentStatus} from "./service";
4-
export {OrderDto} from "./order.dto";
3+
export { PaymentStatus } from './service';
4+
export { OrderDto } from './order.dto';
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { HttpModule, Module } from "@nestjs/common";
2-
import { Service } from "./service";
3-
import { OrdersController } from "./controller";
1+
import { HttpModule, Module } from '@nestjs/common';
2+
import { Service } from './service';
3+
import { OrdersController } from './controller';
44

55
@Module({
66
imports: [HttpModule],
77
providers: [Service],
8-
controllers: [OrdersController]
8+
controllers: [OrdersController],
99
})
10-
export class OrdersModule {
11-
}
10+
export class OrdersModule {}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { IsDefined, IsString } from "class-validator";
1+
import { IsDefined, IsString } from 'class-validator';
22

33
export class OrderDto {
44
@IsString()
55
@IsDefined()
6-
uuid!: string
6+
uuid!: string;
77
}
8-
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
1-
import { HttpService, Injectable } from "@nestjs/common";
1+
import { HttpService, Injectable } from '@nestjs/common';
22

33
export enum PaymentStatus {
44
Started,
55
Pending,
66
Rejected,
7-
Approved
7+
Approved,
88
}
99

1010
@Injectable()
1111
export class Service {
12+
/**
13+
* for brevity, skip real configs
14+
*/
15+
private paymentServiceUrl = process.env.PAYMENT_GATEWAY ?? ""
1216

13-
constructor(
14-
private readonly httpService: HttpService
15-
) {
16-
}
17+
constructor(private readonly httpService: HttpService) {}
1718

1819
async createOrder(
1920
uuid: string,
20-
/**
21-
* for brevity, skip real configs
22-
*/
23-
paymentServiceUrl = process.env.PAYMENT_GATEWAY ?? ""
2421
): Promise<void> {
25-
await this.httpService.post(paymentServiceUrl, {
26-
uuid,
27-
}).toPromise();
22+
await this.httpService
23+
.post(this.paymentServiceUrl, {
24+
uuid,
25+
})
26+
.toPromise();
2827
}
2928

3029
async getOrderStatus(
31-
uuid: string,
32-
/**
33-
* for brevity, skip real configs
34-
*/
35-
paymentServiceUrl = process.env.PAYMENT_GATEWAY ?? ""
30+
uuid: string
3631
): Promise<PaymentStatus> {
37-
const { status } = (await this.httpService.get(paymentServiceUrl + `/${uuid}`).toPromise()).data;
32+
const { status } = (
33+
await this.httpService.get(this.paymentServiceUrl + `/${uuid}`).toPromise()
34+
).data;
3835
return status as PaymentStatus;
39-
};
40-
}
36+
}
37+
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import { INestApplication } from "@nestjs/common";
2-
import { Test } from "@nestjs/testing";
3-
import * as request from "supertest";
1+
import { INestApplication } from '@nestjs/common';
2+
import { Test } from '@nestjs/testing';
3+
import * as request from 'supertest';
44

5-
import {OrdersModule, PaymentStatus} from "../src/orders";
5+
import { OrdersModule, PaymentStatus } from '../src/orders';
66

77
let app: INestApplication;
88

99
/**
1010
* for brevity
1111
*/
12-
const paymentGatewayUrl = "http://localhost:1337"
13-
process.env.PAYMENT_GATEWAY = paymentGatewayUrl
12+
const paymentGatewayUrl = 'http://localhost:1337';
13+
process.env.PAYMENT_GATEWAY = paymentGatewayUrl;
1414

1515
beforeAll(async () => {
1616
const moduleFixture = await Test.createTestingModule({
17-
imports: [OrdersModule]
17+
imports: [OrdersModule],
1818
}).compile();
1919

2020
app = moduleFixture.createNestApplication();
2121
await app.init();
2222
});
2323

2424
describe.skip(`when order was submitted`, () => {
25-
const uuid = "test-order-uuid";
25+
const uuid = 'test-order-uuid';
2626

27-
it("should ACK the order", () => {
27+
it('should ACK the order', () => {
2828
return request(app.getHttpServer())
29-
.post("/")
29+
.post('/')
3030
.send({
31-
uuid
31+
uuid,
3232
})
3333
.expect(201);
3434
});
@@ -48,11 +48,10 @@ describe.skip(`when order was submitted`, () => {
4848
return request(app.getHttpServer())
4949
.get(`/${uuid}`)
5050
.expect(200)
51-
.then(res => {
51+
.then((res) => {
5252
expect(res.body.status).toEqual(PaymentStatus.Approved);
5353
});
5454
});
5555
});
5656
});
57-
58-
});
57+
});
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
import { INestApplication } from "@nestjs/common";
2-
import { Test } from "@nestjs/testing";
3-
import * as request from "supertest";
1+
import { INestApplication } from '@nestjs/common';
2+
import { Test } from '@nestjs/testing';
3+
import * as request from 'supertest';
44

5-
import {OrdersModule, PaymentStatus} from "../src/orders";
5+
import { OrdersModule, PaymentStatus } from '../src/orders';
66

7-
import {start, shutdown, confirmOrder} from "./payment-gateway-fake/bootstrap"
7+
import {
8+
start,
9+
shutdown,
10+
confirmOrder,
11+
} from './payment-gateway-fake/bootstrap';
812

913
let app: INestApplication;
1014

1115
/**
1216
* for brevity
1317
*/
14-
const paymentGatewayUrl = "http://localhost:1337";
18+
const paymentGatewayUrl = 'http://localhost:1337';
1519
process.env.PAYMENT_GATEWAY = paymentGatewayUrl;
1620

1721
beforeAll(async () => {
18-
process.env.PAYMENT_GATEWAY = await start(1337)
22+
process.env.PAYMENT_GATEWAY = await start(1337);
1923
const moduleFixture = await Test.createTestingModule({
20-
imports: [OrdersModule]
24+
imports: [OrdersModule],
2125
}).compile();
2226

2327
app = moduleFixture.createNestApplication();
2428
await app.init();
2529
});
2630

2731
afterAll(async () => {
28-
await app.close()
29-
await shutdown()
30-
})
32+
await app.close();
33+
await shutdown();
34+
});
3135

3236
describe(`when order was submitted`, () => {
33-
const uuid = "test-order-uuid";
34-
it("should ACK the order", () => {
37+
const uuid = 'test-order-uuid';
38+
it('should ACK the order', () => {
3539
return request(app.getHttpServer())
36-
.post("/")
40+
.post('/')
3741
.send({
38-
uuid
42+
uuid,
3943
})
4044
.expect(201);
4145
});
@@ -51,20 +55,18 @@ describe(`when order was submitted`, () => {
5155
});
5256

5357
describe(`when asking for a status after it was completed`, () => {
54-
5558
beforeEach(() => {
56-
confirmOrder(uuid) // clear intention
57-
})
59+
confirmOrder(uuid); // clear intention
60+
});
5861

5962
it(`should return \`approved\` state`, () => {
6063
return request(app.getHttpServer())
6164
.get(`/${uuid}`)
6265
.expect(200)
63-
.then(res => {
66+
.then((res) => {
6467
expect(res.body.status).toEqual(PaymentStatus.Approved);
6568
});
6669
});
6770
});
6871
});
69-
70-
});
72+
});
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import { INestApplication } from "@nestjs/common";
2-
import { Test } from "@nestjs/testing";
3-
import * as request from "supertest";
4-
import AxiosMockAdapter from "axios-mock-adapter";
1+
import { INestApplication } from '@nestjs/common';
2+
import { Test } from '@nestjs/testing';
3+
import * as request from 'supertest';
4+
import AxiosMockAdapter from 'axios-mock-adapter';
55

6-
import {OrdersModule, PaymentStatus} from "../src/orders";
6+
import { OrdersModule, PaymentStatus } from '../src/orders';
77

88
let app: INestApplication;
99
let axiosMock: AxiosMockAdapter;
1010

1111
/**
1212
* for brevity
1313
*/
14-
const paymentGatewayUrl = "http://localhost:1337";
14+
const paymentGatewayUrl = 'http://localhost:1337';
1515
process.env.PAYMENT_GATEWAY = paymentGatewayUrl;
1616

1717
beforeAll(async () => {
1818
const moduleFixture = await Test.createTestingModule({
19-
imports: [OrdersModule]
19+
imports: [OrdersModule],
2020
}).compile();
2121

2222
app = moduleFixture.createNestApplication();
2323
await app.init();
2424

2525
// bind interceptor, force throw on any non-mocked route
26-
axiosMock = new AxiosMockAdapter(app.get("AXIOS_INSTANCE_TOKEN"), {
27-
onNoMatch: "throwException"
26+
axiosMock = new AxiosMockAdapter(app.get('AXIOS_INSTANCE_TOKEN'), {
27+
onNoMatch: 'throwException',
2828
});
2929
});
3030

3131
describe(`when order was submitted`, () => {
32-
const uuid = "test-order-uuid";
32+
const uuid = 'test-order-uuid';
3333

3434
beforeEach(() => {
3535
// "configure" responses
@@ -40,19 +40,19 @@ describe(`when order was submitted`, () => {
4040
.replyOnce(200, {})
4141
.onGet(paymentGatewayUrl + `/${uuid}`)
4242
.replyOnce(200, {
43-
status: PaymentStatus.Pending
43+
status: PaymentStatus.Pending,
4444
})
4545
.onGet(paymentGatewayUrl + `/${uuid}`)
4646
.replyOnce(200, {
47-
status: PaymentStatus.Approved
47+
status: PaymentStatus.Approved,
4848
});
4949
});
5050

51-
it("should ACK the order", () => {
51+
it('should ACK the order', () => {
5252
return request(app.getHttpServer())
53-
.post("/")
53+
.post('/')
5454
.send({
55-
uuid
55+
uuid,
5656
})
5757
.expect(201);
5858
});
@@ -72,11 +72,10 @@ describe(`when order was submitted`, () => {
7272
return request(app.getHttpServer())
7373
.get(`/${uuid}`)
7474
.expect(200)
75-
.then(res => {
75+
.then((res) => {
7676
expect(res.body.status).toEqual(PaymentStatus.Approved);
7777
});
7878
});
7979
});
8080
});
81-
82-
});
81+
});

0 commit comments

Comments
 (0)