Skip to content

Commit 10a35de

Browse files
committed
Refactored to leverage AndcultureCode.JavaScript.Testing - fixes issue #8
1 parent b480982 commit 10a35de

9 files changed

Lines changed: 35 additions & 211 deletions

File tree

package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@types/lodash": "4.14.108",
2121
"@types/node": "13.11.0",
2222
"@types/rosie": "0.0.37",
23+
"andculturecode-javascript-testing": "0.0.1",
2324
"jest": "25.5.4",
2425
"jest-extended": "0.11.5",
2526
"prettier": "1.19.1",

src/__mocks__/axios.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
1-
export default {
2-
defaults: {
3-
headers: {
4-
post: {},
5-
put: {},
6-
},
7-
},
8-
delete: jest.fn(() => Promise.resolve({ data: {} })),
9-
get: jest.fn(() => Promise.resolve({ data: {} })),
10-
interceptors: {
11-
response: {
12-
use: jest.fn(),
13-
},
14-
},
15-
post: jest.fn(() => Promise.resolve({ data: {} })),
16-
put: jest.fn(() => Promise.resolve({ data: {} })),
17-
};
1+
// Hook into jest mocking, but re-export from core
2+
export * from "andculturecode-javascript-testing/dist/mocks/axios";

src/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,9 @@ export * from "./interfaces/service-response";
3434
// -----------------------------------------------------------------------------------------
3535

3636
// factories
37-
export * from "./tests/factories/axios-response-factory";
3837
export * from "./tests/factories/factory-type";
3938
export * from "./tests/factories/stub-resource-record-factory";
4039

41-
// mocks
42-
export * from "./__mocks__/axios";
43-
export * from "./tests/mocks/mock-axios";
44-
4540
// stubs
4641
export * from "./tests/stubs/stub-resource";
4742
export * from "./tests/stubs/stub-resource-record";

src/tests/factories/axios-response-factory.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/tests/factories/factory-type.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const FactoryType = {
2-
AxiosResponse: "AxiosResponse",
32
StubResourceRecord: "StubResourceRecord",
43
};
54

src/tests/factories/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "./axios-response-factory";
1+
export { AxiosResponseFactory } from "andculturecode-javascript-testing";
22
export * from "./stub-resource-record-factory";

src/tests/mocks/mock-axios.ts

Lines changed: 0 additions & 149 deletions
This file was deleted.

src/utilities/service-utils.test.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StubResourceRecord } from "../tests/stubs/stub-resource-record";
33
import { Factory } from "rosie";
44
import { AxiosResponse } from "axios";
55
import { FactoryType } from "../tests/factories/factory-type";
6+
import { FactoryType as AndcultureCodeFactoryType } from "andculturecode-javascript-testing";
67
import { ResultRecord } from "../view-models/result-record";
78
import "jest-extended";
89

@@ -37,7 +38,7 @@ describe("ServiceUtils", () => {
3738
test("when response.data is undefined, it returns the mapped resultObject as undefined", () => {
3839
// Arrange
3940
const axiosResponse = Factory.build<AxiosResponse>(
40-
FactoryType.AxiosResponse,
41+
AndcultureCodeFactoryType.AxiosResponse,
4142
{ data: undefined }
4243
);
4344

@@ -54,7 +55,7 @@ describe("ServiceUtils", () => {
5455
test("when response.data is null, it returns the mapped resultObject as undefined", () => {
5556
// Arrange
5657
const axiosResponse = Factory.build<AxiosResponse>(
57-
FactoryType.AxiosResponse,
58+
AndcultureCodeFactoryType.AxiosResponse,
5859
{ data: null }
5960
);
6061

@@ -71,7 +72,7 @@ describe("ServiceUtils", () => {
7172
test("when response.data.resultObject is undefined, it returns the mapped resultObject as undefined", () => {
7273
// Arrange
7374
const axiosResponse = Factory.build<AxiosResponse>(
74-
FactoryType.AxiosResponse,
75+
AndcultureCodeFactoryType.AxiosResponse,
7576
{
7677
data: {
7778
resultObject: undefined,
@@ -92,7 +93,7 @@ describe("ServiceUtils", () => {
9293
test("when response.data.resultObject is null, it returns the mapped resultObject as undefined", () => {
9394
// Arrange
9495
const axiosResponse = Factory.build<AxiosResponse>(
95-
FactoryType.AxiosResponse,
96+
AndcultureCodeFactoryType.AxiosResponse,
9697
{
9798
data: {
9899
resultObject: null,
@@ -113,7 +114,7 @@ describe("ServiceUtils", () => {
113114
test("it returns rowCount as 1", () => {
114115
// Arrange
115116
const axiosResponse = Factory.build<AxiosResponse>(
116-
FactoryType.AxiosResponse
117+
AndcultureCodeFactoryType.AxiosResponse
117118
);
118119

119120
// Act
@@ -129,7 +130,7 @@ describe("ServiceUtils", () => {
129130
test("it returns the mapped status from the original response", () => {
130131
// Arrange
131132
const axiosResponse = Factory.build<AxiosResponse>(
132-
FactoryType.AxiosResponse
133+
AndcultureCodeFactoryType.AxiosResponse
133134
);
134135

135136
// Act
@@ -145,7 +146,7 @@ describe("ServiceUtils", () => {
145146
test("it returns result as a ResultRecord", () => {
146147
// Arrange
147148
const axiosResponse = Factory.build<AxiosResponse>(
148-
FactoryType.AxiosResponse
149+
AndcultureCodeFactoryType.AxiosResponse
149150
);
150151

151152
// Act
@@ -191,7 +192,7 @@ describe("ServiceUtils", () => {
191192
test("when response.data is undefined, it returns the mapped resultObjects as undefined", () => {
192193
// Arrange
193194
const axiosResponse = Factory.build<AxiosResponse>(
194-
FactoryType.AxiosResponse,
195+
AndcultureCodeFactoryType.AxiosResponse,
195196
{ data: undefined }
196197
);
197198

@@ -208,7 +209,7 @@ describe("ServiceUtils", () => {
208209
test("when response.data is null, it returns the mapped resultObjects as undefined", () => {
209210
// Arrange
210211
const axiosResponse = Factory.build<AxiosResponse>(
211-
FactoryType.AxiosResponse,
212+
AndcultureCodeFactoryType.AxiosResponse,
212213
{ data: null }
213214
);
214215

@@ -225,7 +226,7 @@ describe("ServiceUtils", () => {
225226
test("when response.data.resultObject is undefined, it returns the mapped resultObjects as undefined", () => {
226227
// Arrange
227228
const axiosResponse = Factory.build<AxiosResponse>(
228-
FactoryType.AxiosResponse,
229+
AndcultureCodeFactoryType.AxiosResponse,
229230
{
230231
data: {
231232
resultObject: undefined,
@@ -246,7 +247,7 @@ describe("ServiceUtils", () => {
246247
test("when response.data.resultObject is null, it returns the mapped resultObjects as undefined", () => {
247248
// Arrange
248249
const axiosResponse = Factory.build<AxiosResponse>(
249-
FactoryType.AxiosResponse,
250+
AndcultureCodeFactoryType.AxiosResponse,
250251
{
251252
data: {
252253
resultObject: null,
@@ -271,7 +272,7 @@ describe("ServiceUtils", () => {
271272
2
272273
);
273274
const axiosResponse = Factory.build<AxiosResponse>(
274-
FactoryType.AxiosResponse,
275+
AndcultureCodeFactoryType.AxiosResponse,
275276
{
276277
data: {
277278
resultObject: resultObject,
@@ -292,7 +293,7 @@ describe("ServiceUtils", () => {
292293
test("it returns the mapped status from the original response", () => {
293294
// Arrange
294295
const axiosResponse = Factory.build<AxiosResponse>(
295-
FactoryType.AxiosResponse
296+
AndcultureCodeFactoryType.AxiosResponse
296297
);
297298

298299
// Act
@@ -308,7 +309,7 @@ describe("ServiceUtils", () => {
308309
test("it returns results as a ResultRecord", () => {
309310
// Arrange
310311
const axiosResponse = Factory.build<AxiosResponse>(
311-
FactoryType.AxiosResponse
312+
AndcultureCodeFactoryType.AxiosResponse
312313
);
313314

314315
// Act

0 commit comments

Comments
 (0)