fPaste.me

A free, anonymous, minimalist and open source paste tool.


Untitled
31-07-2021 02:17:03
Anonymous
import http from 'k6/http';
import { check, fail } from 'k6';
import { Rate } from "k6/metrics";
import encoding from 'k6/encoding';

let http_status_100 = new Rate("http_status_100");
let http_status_200 = new Rate("http_status_200");
let http_status_300 = new Rate("http_status_300");
let http_status_400 = new Rate("http_status_400");
let http_status_500 = new Rate("http_status_500");
let success_ratio = new Rate("success_ratio");

// apis/oneWay/buscaVooOW.js
function buscarVooOW(token, context, xSabreCookieEncoded, fromCode, toCode, whenDate)
{
const headers = {
headers:{
'Authorization': `Bearer ${token}`,
'x-sabre-cookie-encoded': xSabreCookieEncoded,
'Content-Type': 'application/json'
},
timeout: 120000
}

const payload = {
airSearch: {
cabinClass: "Economy",
pointOfSale: "BR",
currency: null,
awardBooking: false,
searchType: "BRANDED",
promoCodes: null,
itineraryParts: [{
from: {
code: fromCode,
useNearbyLocations: false
},
to: {
code: toCode,
useNearbyLocations: false
},
when: {
date: whenDate,
},
selectedOfferRef: null,
plusMinusDays: null
}],
passengers: {
ADT: 1,
CHD: 0,
INF: 0
},
trendIndicator: null,
preferredOperatingCarrier: "G3"
}
}

const url = `https://hom-b2c-api.voegol.com.br/api/flights/flights?Flow=Issue&context=${context}`;
const body = JSON.stringify(payload);
const voo = http.post(url, body, headers);

http_status_100.add(voo.status >= 100 && voo.status < 200);
http_status_200.add(voo.status >= 200 && voo.status < 300);
http_status_300.add(voo.status >= 300 && voo.status < 400);
http_status_400.add(voo.status >= 400 && voo.status < 500);
http_status_500.add(voo.status >= 500 && voo.status < 600);
success_ratio.add(voo.json('success') === true);

if (!check(voo, {'buscar voo is successfully': (resp) => resp.status === 200,}))
{
console.log(`Error: Status code = ${voo.status} - ${fromCode}, ${toCode}, ${JSON.stringify(whenDate)}, ${JSON.stringify(voo.body)}`)
}

if (false) {
//debug
console.log(`Error: Status code = ${voo.status} - ${fromCode}, ${toCode}, ${JSON.stringify(whenDate)}, ${JSON.stringify(voo.body)}`)
console.log(`curl https://hom-b2c-api.voegol.com.br/api/flights/flights?Flow=Issue&context=${context} --data '${JSON.stringify(payload)}' \\`);
for (const key in headersGol.headers) {
console.log(`-H "${key}: ${headersGol.headers[key]}" \\`);
}

}
return voo;
}

//utils/data/etinerary.js
const etinerary_json = {
destinations: [
"SDU", "POA", "BSB", "SSA", "FLN",
"REC", "GIG", "CWB", "BEL", "VIX",
"CGB", "FOR", "NVT", "BPS", "MCZ",
"SLZ", "PVH", "JOI", "JPA", "PNZ",
"BVB", "CPV", "XAP", "FEN", "CFB"
]
}

function getOrigin()
{
return "CGH"; //TODO
}

function getDestination()
{
const count = Object.keys(etinerary_json.etinerary).length;
const numberNode = Math.floor(Math.random() * count);

return etinerary_json.destinations[numberNode];
}

// utils/data/date.js
const date_json = {
date: {
departure: "2021-07-30T03:00:00.000Z",
"return": "2021-07-30T23:00:00.000Z"
}
}

function getDate()
{
return date_json.date;
}

export let options = {
insecureSkipTLSVerify: true,
}

export function setup()
{
/*
for (let i = 1; i <= 5; i++) {
options.stages.push({ duration: `1m`, target: i * 10 });
options.stages.push({ duration: `4m`, target: i * 10 });
}

*/
console.log(`Options: ${JSON.stringify(options)}`);
}

export function teardown(data)
{
}

export default function()
{
/*
* Criar token:
$ curl -s https://hom-gol-auth-api.voegol.com.br/api/authentication/create-token \
-H "X-AAT: gfa2skvFLuugOxaTo4u6GMpoN2MHPjHcCB7H1UGBWFQMd6OHR9cECxUNyK2MVM8yfUvVw8hrln1DjkI1aNO85g==" \
-H "redirectUri: https://www.voegol.com.br/callback" | jq -r .response.token
*/

const token = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjkyM0NFMDYyQkI0M0QzRTNFNEEzQUM2MkFENTMwNUMzRDEyNEM3MzIiLCJ4NXQiOiJranpnWXJ0RDAtUGtvNnhpclZNRnc5RWt4ekkiLCJ0eXAiOiJKV1QifQ.eyJkY3QiOiJWREZTVEVGUlNrdHJlRUZ5T1hsdlUzTnlibUo2ZEc5R0wzUXJZMUJvYVdKcFFrUnRVVVl6VUdwdVZGazRXRzQzVFhod01uWm9ZazlCUVVSQmF6a3ZWbkZPUkhKWksyUkplV1JETkM5WGNIRkdXbUZ1VGpOTE1GVkpXak42TWtod2N6Z3pUVGhvVjA5aVVXUlFWekJxVnl0VGJHcHRWVk0yVW1oWGNtVlhUSG80YjBKRk1rZDVWWGRhTURWYWFrOXlWRFk0VlhjNVVURk5aMGcyVUc5U1UyZFFhMFJXVjFNd1VHSlFVM3AyWlZCcVVUTkdhMWRuVm5sVWQxTkdURlZ0TlVsRE5qTkRTamxzUnpsUGNXdDJRVTVCY205dFFrcDVWM2R1VGxCc1VHbFZkVWhETWtSYVJsSXZRazltTVhCbmNXSmljRlkzZWpaYU5tOVNjRkJSU1dJNWRIaFNNRGszV0ZCV1RtaElOVkJQWVdKblZsZExjbnAzVEhrcmNYQlFRemxhTlZFclduRkNjRGhGYVV4VGVIaHFNR1o0Y0RSclNtdGFOdz09IiwibmJmIjoxNjI3NTkwOTUyLCJleHAiOjE2Mjc2NzczNTMsImlhdCI6MTYyNzU5MDk1MywiaXNzIjoiaHR0cHM6Ly9ob20tYXV0aC1hcGkudm9lZ29sLmNsb3VkIiwiYXVkIjoiYjJjLnZvZWdvbC5jb20uYnIvQ0VSVCJ9.qk5MSAXmjNnArQfok3z-AOD1XuV_IQh7TpJvQCIRuAkxKead9ZG9yQN4cMaCsKxiRMzy8TZgfGbi_7i2MAZpMXuSXzVHatf50xTVIkDoTkGx9vWIMX0tIzkteDbFrqA2ZmbL40JJnasvJBx8WfuyKs7khXbZUwpBRpOnDpS7oyISVCtTtUs_YBfTXNRymKInCuc-xdT-FMNy_OpnKWrAaa9dSusfhO3NF85iIxeg1QTI1kdQc-6UKGqsqyuLn9m_zHdh3ACC5gwnvUEdb4Qav9LP1cZgtA4Ja9IsmjV1z7K9LFwRzhFjAaCDWFg4ijg6KZKyl676j9wCQc43BkKSpA";
const context = "B2C";
const origin = getOrigin();
const destination = "SDU"; //getDestination();
const date = getDate()["departure"];

const voo = buscarVooOW(token, context, "", origin, destination, date);
}