Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function setShippingAddressAndCustomer() {
const result = setShippingAddressMutation.post({
address: {
countryCode: 'GB',
streetLine1: '123 Test Street',
},
customer: {
emailAddress: `test-user-${Math.random().toString(32).substr(3)}@mail.com`,
firstName: `Test`,
lastName: `User`,
},
});
check(result.data, {
'Address set': r => r.setOrderShippingAddress.shippingAddress.country === 'United Kingdom',
});
}
export default function() {
const itemsToAdd = Math.ceil(Math.random() * 10);
for (let i = 0; i < itemsToAdd; i ++) {
searchProducts();
const product = findAndLoadProduct();
addToCart(randomItem(product.variants).id);
}
setShippingAddressAndCustomer();
const data = getShippingMethodsQuery.post().data;
const result = completeOrderMutation.post({ id: data.eligibleShippingMethods[0].id }).data;
check(result, {
'Order completed': r => r.addPaymentToOrder.state === 'PaymentAuthorized',
});
}
function addToCart(variantId) {
const qty = Math.ceil(Math.random() * 4);
const result = addItemToOrderMutation.post({ id: variantId, qty });
check(result.data, {
'Product added to cart': r => !!r.addItemToOrder.lines
.find(l => l.productVariant.id === variantId && l.quantity >= qty),
});
}
export default () => {
const requestClaim = http.get(`${CLAIM_HOST}`)
const url = `${NODE_HOST}/works`
const payload = requestClaim.body
const params = { headers: { 'Content-Type': 'application/json' } }
const work = http.post(url, payload, params)
check(work, {
'status 202': (r) => r.status === 202
})
sleep(1 + parseInt(DELAY_GET_WORK))
const id = JSON.parse(work.request.body).id
const urlGetWork = `${NODE_HOST}/works/${id}`
const res = http.get(urlGetWork)
check(res, {
'status 200': (r) => r.status === 200
})
sleep(1)
}
export default function () {
check(http.get('http://server.localhost/test.html'), {
'is status 200': (r) => r.status === 200
})
}
test (name, logic) {
if (state.test) {
throw new Error('Nested pm.test calls not allowed')
}
try {
enterTest()
logic()
k6.check(store.response, { [name]: response => {
for (const test of store.test) {
if (!test(response)) {
return false
}
}
return true
} })
} catch (error) {
const AssertionError = postman[Extend].AssertionError
if (AssertionError && error instanceof AssertionError) {
k6.check(null, { [name]: () => false })
} else {
throw error
}
} finally {
exitTest()
const makeGetRequest = () => {
const response = http.get(`${BASE_URL}${RESOURCE_PATH}`,
{
headers: {
Accept: 'application/json'
},
tags: {
name: 'Get resource request'
}
})
check(response, {
'status code is 200': r => r.status === 200
})
}
const makePostRequest = () => {
const response = http.post(`${BASE_URL}${RESOURCE_PATH}`,
patient,
{
headers: {
'Content-Type': 'application/json'
},
tags: {
name: `Create Patient Stress Test`
}
})
check(response, {
'status code is 201': r => r.status === 201
})
}
function makeGetRequestWithDateRangeFilter () {
const query = encodeURIComponent(`{"request.timestamp":"{\\"$gte\\":${startDate},\\"$lte\\":${endDate}}"}`)
const response = http.get(
`${BASE_URL}/transactions?filterLimit=100&filters=${query}`,
{
headers: Object.assign(getTestAuthHeaders(), {
Accept: 'application/json',
'Content-Type': 'apllication/json'
}),
tags: {
name: 'Transactions with Date Range Filter'
}
}
)
check(response, {
'status code is 200': r => r.status === 200
})
}
function getMetricsByMonth() {
const res = http.get(
`${BASE_URL}/metrics/timeseries/month?startDate=2017-01-01&endDate=2017-12-31`,
{
headers: Object.assign(getTestAuthHeaders(), {
Accept: 'application/json'
}),
tags: {
name: 'All metrics by month'
}
}
)
check(res, {
'status code is 200': r => r.status === 200
})
}