generated from whyk-pg/learn-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Postman CollectionのexecをTypeScriptで書けるように修正
- Loading branch information
1 parent
7c5a696
commit 9caba46
Showing
3 changed files
with
168 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { Collection } from "postman-collection"; | ||
|
||
declare namespace Postman { | ||
interface PM { | ||
test( | ||
testName: string, | ||
specFunction: (done?: (error?: unknown) => void) => void, | ||
): void; | ||
expect: Chai.ExpectStatic; | ||
response: { | ||
to: Chai.Assertion; | ||
json(): { | ||
status: number; | ||
method: string; | ||
text: string; | ||
[key: string]: string | number; | ||
}; | ||
text(): string; | ||
}; | ||
} | ||
} | ||
|
||
declare const pm: Postman.PM; | ||
|
||
const convertPostmanTestToStringArray = (pmTest: () => void): string[] => { | ||
// TODO: 実行に支障はないが、出力されたexecがすごく汚いので、どうにかして直したい | ||
return [pmTest.toString().replace(/\(\)\=\>(.*)/g, "$1")]; | ||
}; | ||
|
||
export const collection = new Collection({ | ||
name: "verify-cfw-drizzle-crud", | ||
item: [ | ||
{ | ||
name: "GET", | ||
event: [ | ||
{ | ||
listen: "test", | ||
script: { | ||
exec: convertPostmanTestToStringArray(() => | ||
pm.test("レスポンスボディのJSONが想定通りか", () => { | ||
const jsonData = pm.response.json(); | ||
pm.expect(jsonData.status).to.eql(200); | ||
pm.expect(jsonData.method).to.eql("GET"); | ||
pm.expect(jsonData.text).to.eql("OK!"); | ||
pm.expect(jsonData.apiKey).to.eql("Example_0000"); | ||
}), | ||
), | ||
type: "text/javascript", | ||
}, | ||
}, | ||
], | ||
request: { | ||
method: "GET", | ||
header: [], | ||
url: { | ||
protocol: "http", | ||
host: ["localhost"], | ||
port: "8787", | ||
}, | ||
}, | ||
response: [], | ||
}, | ||
{ | ||
name: "POST", | ||
event: [ | ||
{ | ||
listen: "test", | ||
script: { | ||
exec: convertPostmanTestToStringArray(() => | ||
pm.test("レスポンスボディのJSONが想定通りか", () => { | ||
const jsonData = pm.response.json(); | ||
pm.expect(jsonData.status).to.eql(200); | ||
pm.expect(jsonData.method).to.eql("POST"); | ||
pm.expect(jsonData.text).to.eql("OK!"); | ||
pm.expect(jsonData.apiKey).to.eql("Example_0000"); | ||
}), | ||
), | ||
type: "text/javascript", | ||
}, | ||
}, | ||
], | ||
request: { | ||
method: "POST", | ||
header: [], | ||
url: { | ||
protocol: "http", | ||
host: ["localhost"], | ||
port: "8787", | ||
}, | ||
}, | ||
response: [], | ||
}, | ||
{ | ||
name: "PATCH", | ||
event: [ | ||
{ | ||
listen: "test", | ||
script: { | ||
exec: convertPostmanTestToStringArray(() => | ||
pm.test("レスポンスボディのJSONが想定通りか", () => { | ||
const jsonData = pm.response.json(); | ||
pm.expect(jsonData.status).to.eql(200); | ||
pm.expect(jsonData.method).to.eql("PATCH"); | ||
pm.expect(jsonData.text).to.eql("OK!"); | ||
pm.expect(jsonData.apiKey).to.eql("Example_0000"); | ||
}), | ||
), | ||
type: "text/javascript", | ||
}, | ||
}, | ||
], | ||
request: { | ||
method: "PATCH", | ||
header: [], | ||
url: { | ||
protocol: "http", | ||
host: ["localhost"], | ||
port: "8787", | ||
}, | ||
}, | ||
response: [], | ||
}, | ||
{ | ||
name: "DELETE", | ||
event: [ | ||
{ | ||
listen: "test", | ||
script: { | ||
exec: convertPostmanTestToStringArray(() => | ||
pm.test("レスポンスボディのJSONが想定通りか", () => { | ||
const jsonData = pm.response.json(); | ||
pm.expect(jsonData.status).to.eql(200); | ||
pm.expect(jsonData.method).to.eql("DELETE"); | ||
pm.expect(jsonData.text).to.eql("OK!"); | ||
pm.expect(jsonData.apiKey).to.eql("Example_0000"); | ||
}), | ||
), | ||
type: "text/javascript", | ||
}, | ||
}, | ||
], | ||
request: { | ||
method: "DELETE", | ||
header: [], | ||
url: { | ||
protocol: "http", | ||
host: ["localhost"], | ||
port: "8787", | ||
}, | ||
}, | ||
response: [], | ||
}, | ||
], | ||
}); |
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
Oops, something went wrong.