Skip to content

Commit 47e6187

Browse files
Merge pull request #2 from wintondeshong/master
RouteUtils, ServiceUtils, Testing actors, and more types
2 parents 48008c1 + 676d0ef commit 47e6187

19 files changed

Lines changed: 1103 additions & 1 deletion

package-lock.json

Lines changed: 32 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
@@ -8,6 +8,7 @@
88
"url": "https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/issues"
99
},
1010
"dependencies": {
11+
"axios": "0.19.2",
1112
"immutable": "4.0.0-rc.12"
1213
},
1314
"description": "Common patterns, functions, etc... used when building react applications",

src/__mocks__/axios.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
};

src/enumerations/content-type.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
enum ContentType {
2+
Css = "text/css",
3+
Html = "text/html",
4+
Javascript = "text/javascript",
5+
Json = "application/json",
6+
Pdf = "application/pdf",
7+
Xml = "application/xml",
8+
}
9+
10+
export { ContentType };

src/enumerations/http-header.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum HttpHeader {
2+
Accept = "Accept",
3+
ContentType = "Content-Type",
4+
}
5+
6+
export { HttpHeader };

src/enumerations/http-verb.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
enum HttpVerb {
2+
Delete = "DELETE",
3+
Get = "GET",
4+
Patch = "PATCH",
5+
Post = "POST",
6+
Put = "PUT",
7+
}
8+
9+
export { HttpVerb };

src/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// #region Enumerations
33
// -----------------------------------------------------------------------------------------
44

5+
export * from "./enumerations/content-type";
56
export * from "./enumerations/error-type";
7+
export * from "./enumerations/http-header";
8+
export * from "./enumerations/http-verb";
69

710
//#endregion Enumerations
811

@@ -13,16 +16,38 @@ export * from "./enumerations/error-type";
1316
export * from "./interfaces/paged-result";
1417
export * from "./interfaces/result";
1518
export * from "./interfaces/result-error";
19+
export * from "./interfaces/service-response";
1620

1721
//#endregion Interfaces
1822

23+
// -----------------------------------------------------------------------------------------
24+
// #region Tests
25+
// -----------------------------------------------------------------------------------------
26+
27+
// factories
28+
export * from "./tests/factories/axios-response-factory";
29+
export * from "./tests/factories/factory-type";
30+
export * from "./tests/factories/stub-resource-record-factory";
31+
32+
// mocks
33+
export * from "./__mocks__/axios";
34+
export * from "./tests/mocks/mock-axios";
35+
36+
// stubs
37+
export * from "./tests/stubs/stub-resource";
38+
export * from "./tests/stubs/stub-resource-record";
39+
40+
//#endregion Tests
41+
1942
// -----------------------------------------------------------------------------------------
2043
// #region Utilities
2144
// -----------------------------------------------------------------------------------------
2245

2346
export * from "./utilities/collection-utils";
2447
export * from "./utilities/core-utils";
2548
export * from "./utilities/promise-factory";
49+
export * from "./utilities/route-utils";
50+
export * from "./utilities/service-utils";
2651
export * from "./utilities/string-utils";
2752

2853
//#endregion Utilities

src/interfaces/service-response.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ResultRecord } from "../view-models/result-record";
2+
3+
interface ServiceResponse<T> {
4+
/**
5+
* Result object containing detailed response information,
6+
* such as; errors, result data, etc...
7+
*/
8+
result?: ResultRecord<T>;
9+
results?: ResultRecord<T[]>;
10+
11+
/**
12+
* Convenience property to read result's nested record
13+
*/
14+
resultObject?: T;
15+
resultObjects?: T[];
16+
17+
/**
18+
* Totoal possible records available for the initial service request. If greater
19+
* than total results in this response, additional pages of results can be
20+
* requested from the API
21+
*/
22+
rowCount: number;
23+
24+
/**
25+
* HTTP status code of the response
26+
*/
27+
status: number;
28+
}
29+
30+
export { ServiceResponse };
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Factory } from "rosie";
2+
import { FactoryType } from "./factory-type";
3+
import { AxiosResponse } from "axios";
4+
5+
// -----------------------------------------------------------------------------------------
6+
// #region Factory
7+
// -----------------------------------------------------------------------------------------
8+
9+
const AxiosResponseFactory = Factory.define<AxiosResponse>(
10+
FactoryType.AxiosResponse
11+
)
12+
.sequence("status", () => 200)
13+
.sequence("statusText", () => "OK");
14+
15+
// #endregion Factory
16+
17+
// -----------------------------------------------------------------------------------------
18+
// #region Export
19+
// -----------------------------------------------------------------------------------------
20+
21+
export { AxiosResponseFactory };
22+
23+
// #endregion Export
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const FactoryType = {
2+
AxiosResponse: "AxiosResponse",
3+
StubResourceRecord: "StubResourceRecord",
4+
};
5+
6+
export { FactoryType };

0 commit comments

Comments
 (0)