本文整理匯總了TypeScript中integration-test/helpers/clients/base/request.request函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript request函數的具體用法?TypeScript request怎麽用?TypeScript request使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了request函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getPin
static getPin (letterHolderId: string): Promise<string> {
const options = {
uri: `${baseURL}/testing-support/accounts/pin/${letterHolderId}`,
resolveWithFullResponse: true,
rejectUnauthorized: false,
json: false
}
return request(options).then(function (response) {
return response.body
})
}
示例2: retrieveUser
/**
* Retrieves uses details
*
* @param {string} jwt
* @returns {Promise<User>}
*/
static retrieveUser (jwt: string): Promise<User> {
const options = {
uri: `${baseURL}/details`,
headers: {
Authorization: `Bearer ${jwt}`
}
}
return request(options).then(function (response) {
return response
})
}
示例3: addRoleToUser
static addRoleToUser (bearerToken: string, role: string): Promise<void> {
if (!bearerToken) {
return Promise.reject(new Error('bearerToken is required'))
}
const options = {
method: 'POST',
uri: `${baseURL}/user/roles`,
body: { role: role },
headers: {
Authorization: `Bearer ${bearerToken}`
}
}
return request(options).then()
}
示例4: exchangeCode
static exchangeCode (code: string): Promise<string> {
const options = {
method: 'POST',
uri: `${baseURL}/oauth2/token`,
auth: {
username: oauth2.client_id,
password: oauth2.client_secret
},
form: { grant_type: 'authorization_code', code: code, redirect_uri: oauth2.redirect_uri }
}
return request(options).then(function (response) {
return response['access_token']
})
}
示例5: linkDefendant
/**
* Links defendant to claim in the claim store
*
* @param {string} defendant - defendant ID
* @returns {Promise<Claim>}
*/
static linkDefendant (defendant: User): Promise<Claim> {
if (!defendant) {
return Promise.reject('Defendant is required')
}
const options = {
method: 'PUT',
uri: `${baseURL}/claims/defendant/link`,
headers: {
Authorization: `Bearer ${defendant.bearerToken}`
}
}
return request(options).then(function (response) {
return response
})
}
示例6: retrieveByReferenceNumber
/**
* Retrieves claim from the claim store by claim reference number
*
* @param {string} referenceNumber - claim reference number
* @param {User} owner - claim owner
* @returns {Promise<Claim>}
*/
static retrieveByReferenceNumber (referenceNumber: string, owner: User): Promise<Claim> {
if (!referenceNumber) {
return Promise.reject('Claim reference number is required')
}
if (!owner) {
return Promise.reject('Claim owner is required')
}
const options = {
uri: `${baseURL}/claims/${referenceNumber}`,
headers: {
Authorization: `Bearer ${owner.bearerToken}`
}
}
return request(options).then(function (response) {
return response
})
}
示例7: authenticateUser
/**
* Authenticate user
*
* @param {string} username the username to authenticate
* @param password the users password (optional, default will be used if none provided)
* @returns {Promise<string>} the users access token
*/
static async authenticateUser (username: string, password: string = undefined): Promise<string> {
const base64Authorisation: string = IdamClient.toBase64(`${username}:${password || defaultPassword}`)
const oauth2Params: string = IdamClient.toUrlParams(oauth2)
const options = {
method: 'POST',
uri: `${baseURL}/oauth2/authorize?response_type=code&${oauth2Params}`,
headers: {
Authorization: `Basic ${base64Authorisation}`,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
return request(options).then(function (response) {
return response.code
}).then(function (response) {
return IdamClient.exchangeCode(response).then(function (response) {
return response
})
})
}
示例8: createUser
/**
* Creates user with default password
*
* @param {string} email
* @param {string} userGroupCode
* @param password the user's password, will use a default if undefined
* @returns {Promise<void>}
*/
static createUser (email: string, userGroupCode: string, password: string = undefined): Promise<void> {
const options = {
method: 'POST',
uri: `${baseURL}/testing-support/accounts`,
body: {
email: email,
forename: 'John',
surname: 'Smith',
levelOfAccess: 0,
userGroup: {
code: userGroupCode
},
activationDate: '',
lastAccess: '',
password: password ? password : defaultPassword
}
}
return request(options).then(function () {
return Promise.resolve()
})
}
示例9: authenticatePinUser
/**
* Authorizes pin user
*
* @param {string} pin
* @returns {Promise<string>} bearer token
*/
static async authenticatePinUser (pin: string): Promise<string> {
const oauth2Params: string = IdamClient.toUrlParams(oauth2)
const options = {
uri: `${baseURL}/pin?${oauth2Params}`,
headers: {
pin,
'Content-Type': 'application/x-www-form-urlencoded'
},
simple: false,
followRedirect: false,
json: false,
resolveWithFullResponse: true
}
return request(options).then(function (response) {
return response
}).then(function (response) {
const code: any = url.parse(response.headers.location, true).query.code
return IdamClient.exchangeCode(code).then(function (response) {
return response
})
})
}
示例10: respond
/**
* Saves response to a claim identified by the ID in the claim store
*
* @param {number} externalId - claim external ID
* @param {any} responseData - response data
* @param {User} defendant - user that makes response
* @returns {Promise<Claim>}
*/
static respond (externalId: string, responseData: ResponseData, defendant: User): Promise<Claim> {
if (!externalId) {
return Promise.reject('Claim ID is required')
}
if (!responseData) {
return Promise.reject('Response data is required')
}
if (!defendant) {
return Promise.reject('Defendant is required')
}
const options = {
method: 'POST',
uri: `${baseURL}/responses/claim/${externalId}/defendant/${defendant.id}`,
body: responseData,
headers: {
Authorization: `Bearer ${defendant.bearerToken}`
}
}
return request(options).then(function (response) {
return response
})
}