Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagofrancafernandes/dd93e29cefd011cee48a8789c5cccc89 to your computer and use it in GitHub Desktop.
Save tiagofrancafernandes/dd93e29cefd011cee48a8789c5cccc89 to your computer and use it in GitHub Desktop.
dev-postman_snippets
//--------------------------------------------------------------------------------
//START
const template_success = `
<div style="background:#fff;">
access_token: <em>(ocultado)</em> Salvo nas variáveis de ambiente<br>
token_type: {{token_type}}<br>
expires_in: {{expires_in}}min<br>
</div>
`;
const template_error = `
<div style="background:red;color:white;">
Erro!<br>
status_code: {{status_code}}
</div>
`;
if(tests["Status code is 201"] = responseCode.code === 201)
{
pm.visualizer.set(template_success, {
...pm.response.json(),
token_type: pm.response.json().content?.token?.token_type,
expires_in: '',//parseInt(pm.response.json().content?.token?.expires_in) / 60
});
}else{
{
pm.visualizer.set(template_error, {
...pm.response.json(),
status_code: parseInt(responseCode.code)
});
}
}
// Guarda o access_token em uma variável de ambiente da collection
pm.test("Token is available", function () {
const access_token = pm.response.json().content?.token?.access_token;
pm.expect(access_token).not.eq(undefined);
// Guarda o "access_token" obtido
// (será utilizado pelas demais requisições)
pm.collectionVariables.set("TOKEN", access_token);
});
//END
//--------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment