-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
2,054 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Request, Response } from "express"; | ||
import ApiResponseHandler from "api-response-handler"; | ||
import { runTest } from "~/services/testing/runTests"; | ||
|
||
export const runTestHandler = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<void> => { | ||
console.log(req.body); | ||
runTest(req.body.test); | ||
await ApiResponseHandler.success(res, null); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
BaseEntity, | ||
Column, | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
} from "typeorm"; | ||
import { ApiEndpoint } from "models/api-endpoint"; | ||
|
||
@Entity() | ||
export class ApiEndpointTest extends BaseEntity { | ||
@PrimaryGeneratedColumn("uuid") | ||
uuid: string; | ||
|
||
@Column({ nullable: false }) | ||
name: string; | ||
|
||
@Column({ type: "jsonb", nullable: true }) | ||
tags: string[]; | ||
|
||
@Column({ type: "jsonb", nullable: true }) | ||
requests: Request[]; | ||
|
||
@ManyToOne(() => ApiEndpoint) | ||
@JoinColumn() | ||
apiEndpoint: ApiEndpoint; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import newman from "newman"; | ||
import { | ||
CollectionDefinition, | ||
RequestDefinition, | ||
RequestBodyDefinition, | ||
} from "postman-collection"; | ||
import { RequestBodyType } from "../../../../common/src/testing/enums"; | ||
import { Request } from "../../../../common/src/testing/types"; | ||
import { Test } from "../../../../common/src/testing/types"; | ||
|
||
const requestToItem = (e: Request, i: number) => { | ||
const event = e.tests.trim() | ||
? [ | ||
{ | ||
listen: "test", | ||
script: { | ||
type: "text/javascript", | ||
exec: e.tests.split("\n"), | ||
}, | ||
}, | ||
] | ||
: []; | ||
let body: RequestBodyDefinition = { mode: "raw" }; | ||
if (e.body.type == RequestBodyType.JSON) { | ||
body.raw = e.body.data as string; | ||
} | ||
let url: string = e.url; | ||
if (e.params.length > 0) { | ||
url = `${url}?${e.params.map((p) => `${p.key}=${p.value}`).join("&")}`; | ||
} | ||
let item = { | ||
name: `Request ${i}`, | ||
event: event, | ||
request: { | ||
url: e.url, | ||
method: e.method, | ||
header: e.headers, | ||
body: body, | ||
} as RequestDefinition, | ||
}; | ||
return item; | ||
}; | ||
|
||
export const runTest = (e: Test) => { | ||
const items = e.requests.map(requestToItem); | ||
const collection: CollectionDefinition = { | ||
info: { | ||
name: "Sample Postman Collection", | ||
}, | ||
item: items, | ||
}; | ||
const res = newman.run( | ||
{ | ||
collection, | ||
}, | ||
(a, b) => { | ||
console.log(JSON.stringify(a, null, 4)); | ||
console.log(JSON.stringify(b, null, 4)); | ||
} | ||
); | ||
}; |
Oops, something went wrong.