newman-collection
Advanced tools
Comparing version 1.1.3 to 1.2.0
61
index.js
@@ -6,11 +6,10 @@ "use strict"; | ||
class NewmanRequestAuth { | ||
constructor(auth) { | ||
this.auth = auth; | ||
constructor(request) { | ||
this.request = request; | ||
} | ||
basic(basic) { | ||
// this.auth. | ||
// Object.assign(this.auth, { | ||
// type: "basic", | ||
// basic: Object.keys(basic).map() | ||
// }); | ||
let { request } = this.request; | ||
request.authorizeUsing({ type: "basic" }); | ||
request.auth.update(Object.keys(basic).map(key => ({ key, value: basic[key] }))); | ||
return this.request; | ||
} | ||
@@ -23,2 +22,5 @@ } | ||
} | ||
get postman_item() { | ||
return this.item.postman_item; | ||
} | ||
// auth(auth: NewmanRequestAuth):NewmanRequest { | ||
@@ -30,3 +32,3 @@ // Object.assign(this.request.auth, auth); | ||
Object.keys(events).forEach(key => { | ||
this.item.events.append(new postman_collection_1.Event({ | ||
this.postman_item.events.append(new postman_collection_1.Event({ | ||
listen: key, | ||
@@ -51,7 +53,28 @@ script: { | ||
} | ||
get auth() { | ||
return new NewmanRequestAuth(this); | ||
} | ||
get pm() { | ||
return { | ||
test: (description, callback) => { | ||
this.postman_item.events.append(new postman_collection_1.Event({ | ||
listen: "test", | ||
script: { | ||
exec: [`pm.test(\"${description}\", ${callback.toString()});`] | ||
.map(code => code.split("\r\n")) | ||
.flat() | ||
} | ||
})); | ||
return this; | ||
} | ||
}; | ||
} | ||
} | ||
class NewmanCollectionItem { | ||
constructor(item) { | ||
this.item = new postman_collection_1.Item(item); | ||
constructor(def) { | ||
this.postman_item = new postman_collection_1.Item(def); | ||
} | ||
get item() { | ||
return this; | ||
} | ||
static new(name) { | ||
@@ -61,4 +84,4 @@ return new NewmanCollectionItem({ name }); | ||
request(request) { | ||
Object.assign(this.item.request, request); | ||
return new NewmanRequest(this.item.request, this.item); | ||
Object.assign(this.postman_item.request, request); | ||
return new NewmanRequest(this.postman_item.request, this); | ||
} | ||
@@ -89,12 +112,18 @@ get(url) { | ||
class NewmanCollection { | ||
constructor(collection) { | ||
this.collection = new postman_collection_1.Collection(collection); | ||
constructor(collection, items) { | ||
this.collection = new postman_collection_1.Collection(typeof collection === "object" | ||
? collection | ||
: undefined); | ||
this.items = Array.isArray(collection) | ||
? collection | ||
: items; | ||
} | ||
item(name) { | ||
let item = new NewmanCollectionItem({ name }); | ||
this.collection.items.append(item.item); | ||
this.collection.items.append(item.postman_item); | ||
return item; | ||
} | ||
set items(items) { | ||
items.forEach(item => this.collection.items.append(item.item)); | ||
items && | ||
items.forEach(element => this.collection.items.append(element.item.postman_item)); | ||
} | ||
@@ -101,0 +130,0 @@ } |
117
index.ts
@@ -16,15 +16,27 @@ import { | ||
interface INewmanEventEmitter { | ||
on(events: INewmanEvents): INewmanEventEmitter; | ||
} | ||
// interface INewmanEventEmitter { | ||
// on(events: INewmanEvents): INewmanEventEmitter; | ||
// } | ||
interface INewmanRequestAuthBasic { | ||
user: string; | ||
username: string; | ||
password: string; | ||
} | ||
interface INewmanRequest extends INewmanEventEmitter { | ||
interface INewmanRequestAuth { | ||
basic(basic: INewmanRequestAuthBasic): void; | ||
} | ||
interface INewmanPmAPI { | ||
test(desription: string, callback: Function): INewmanRequest; | ||
} | ||
interface INewmanRequest extends INewmanItemElement { | ||
request: Request; | ||
postman_item: Item; | ||
body(body: string): INewmanRequest; | ||
on(events: INewmanEvents): INewmanRequest; | ||
headers(headers: object): INewmanRequest; | ||
auth: INewmanRequestAuth; | ||
pm: INewmanPmAPI; | ||
} | ||
@@ -36,3 +48,8 @@ | ||
interface INewmanItem { | ||
interface INewmanItemElement { | ||
//extends INewmanEventEmitter | ||
item: INewmanItem; | ||
} | ||
interface INewmanItem extends INewmanItemElement { | ||
get: NewmanRequestCall; | ||
@@ -45,2 +62,3 @@ post: NewmanRequestCall; | ||
patch: NewmanRequestCall; | ||
postman_item: Item; | ||
} | ||
@@ -50,13 +68,15 @@ | ||
class NewmanRequestAuth { | ||
auth: RequestAuthDefinition; | ||
constructor(auth: RequestAuthDefinition) { | ||
this.auth = auth; | ||
class NewmanRequestAuth implements INewmanRequestAuth { | ||
request: INewmanRequest; | ||
constructor(request: INewmanRequest) { | ||
this.request = request; | ||
} | ||
basic(basic: INewmanRequestAuthBasic) { | ||
// this.auth. | ||
// Object.assign(this.auth, { | ||
// type: "basic", | ||
// basic: Object.keys(basic).map() | ||
// }); | ||
let { request } = this.request; | ||
request.authorizeUsing({ type: "basic" }); | ||
request.auth.update( | ||
Object.keys(basic).map(key => ({ key, value: basic[key] })) | ||
); | ||
return this.request; | ||
} | ||
@@ -67,4 +87,8 @@ } | ||
request: Request; | ||
item: Item; | ||
constructor(request: Request, item: Item) { | ||
get postman_item() { | ||
return this.item.postman_item; | ||
} | ||
item: INewmanItem; | ||
constructor(request: Request, item: INewmanItem) { | ||
this.request = request; | ||
@@ -79,3 +103,3 @@ this.item = item; | ||
Object.keys(events).forEach(key => { | ||
this.item.events.append( | ||
this.postman_item.events.append( | ||
new Event({ | ||
@@ -104,9 +128,33 @@ listen: key, | ||
} | ||
get auth(): INewmanRequestAuth { | ||
return new NewmanRequestAuth(this); | ||
} | ||
get pm(): INewmanPmAPI { | ||
return { | ||
test: (description, callback) => { | ||
this.postman_item.events.append( | ||
new Event({ | ||
listen: "test", | ||
script: { | ||
exec: [`pm.test(\"${description}\", ${callback.toString()});`] | ||
.map(code => code.split("\r\n")) | ||
.flat() | ||
} | ||
}) | ||
); | ||
return this; | ||
} | ||
}; | ||
} | ||
} | ||
export class NewmanCollectionItem implements INewmanItem { | ||
item: Item; | ||
constructor(item: ItemDefinition) { | ||
this.item = new Item(item); | ||
postman_item: Item; | ||
constructor(def: ItemDefinition) { | ||
this.postman_item = new Item(def); | ||
} | ||
get item() { | ||
return this; | ||
} | ||
static new(name: string): NewmanCollectionItem { | ||
@@ -116,4 +164,4 @@ return new NewmanCollectionItem({ name }); | ||
request(request: RequestDefinition): INewmanRequest { | ||
Object.assign(this.item.request, request); | ||
return new NewmanRequest(this.item.request, this.item); | ||
Object.assign(this.postman_item.request, request); | ||
return new NewmanRequest(this.postman_item.request, this); | ||
} | ||
@@ -149,13 +197,26 @@ get(url: string) { | ||
collection: Collection; | ||
constructor(collection: CollectionDefinition) { | ||
this.collection = new Collection(collection); | ||
constructor( | ||
collection?: CollectionDefinition | Array<INewmanItemElement>, | ||
items?: Array<INewmanItemElement> | ||
) { | ||
this.collection = new Collection( | ||
typeof collection === "object" | ||
? (collection as CollectionDefinition) | ||
: undefined | ||
); | ||
this.items = Array.isArray(collection) | ||
? (collection as Array<NewmanCollectionItem>) | ||
: items; | ||
} | ||
item(name: string): NewmanCollectionItem { | ||
let item = new NewmanCollectionItem({ name }); | ||
this.collection.items.append(item.item); | ||
this.collection.items.append(item.postman_item); | ||
return item; | ||
} | ||
set items(items: Array<NewmanCollectionItem>) { | ||
items.forEach(item => this.collection.items.append(item.item)); | ||
set items(items: Array<INewmanItemElement>) { | ||
items && | ||
items.forEach(element => | ||
this.collection.items.append(element.item.postman_item) | ||
); | ||
} | ||
} |
{ | ||
"name": "newman-collection", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const { NewmanCollectionItem } = require("../../index"); | ||
module.exports = NewmanCollectionItem.new("Test GET request"); | ||
module.exports.get("https://postman-echo.com/get?foo1=bar1&foo2=bar2").on({ | ||
test() { | ||
console.log("Test is reached"); | ||
} | ||
}); | ||
module.exports = NewmanCollectionItem.new("Test GET request") | ||
.get("https://postman-echo.com/get?foo1=bar1&foo2=bar2") | ||
.pm.test("Endpoint is reached", () => { | ||
pm.response.to.be.ok; | ||
}); |
const { NewmanCollectionItem } = require("../../index"); | ||
module.exports = NewmanCollectionItem.new("Test POST request"); | ||
module.exports | ||
module.exports = NewmanCollectionItem.new("Test POST request") | ||
.post("https://postman-echo.com/post") | ||
.headers({ "Content-Type": "text/plain" }) | ||
.body("test") | ||
.on({ | ||
test() { | ||
pm.test("body should be same", () => { | ||
pm.response.to.have.jsonBody("data", "test"); | ||
}); | ||
} | ||
.pm.test("body should be same", () => { | ||
pm.response.to.have.jsonBody("data", "test"); | ||
}); |
const { NewmanCollection } = require("../../index"); | ||
module.exports = new NewmanCollection(); | ||
module.exports.items = [require("./get"), require("./post")]; | ||
module.exports = new NewmanCollection([ | ||
require("./get"), | ||
require("./post"), | ||
require("./basic_auth") | ||
]); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34964
14
1043