Last active
May 20, 2022 23:08
-
-
Save tiagofrancafernandes/dd93e29cefd011cee48a8789c5cccc89 to your computer and use it in GitHub Desktop.
dev-postman_snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------------------------- | |
//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