I have following issue. I'm starting to create e2e api tests the aim of first test is to get unauthorized user token, second test use value from first test in method header and returning token for authorized user - and after all, second token will be used in further tests. How to save value of tokens in variable and pass it through tests?
I'm new in JS and now i received 'ReferenceError: auth_token is not defined'
const chai = require('chai');
const request = require('request-promise-native');
const mocha = require('mocha');
const config = require('../config');
const assert = chai.assert;
//const describe = mocha.describe;
//const it = mocha.it;
// request.debug = true;
describe('0_auth', () => {
it('should return token for unauthorized user', async () => {
const result = await request({
headers: config.headers,
url: `${config.url}/rest/v1/auth/get-token`,
method: "POST",
json: {
"deviceUuidSource": "DEVICE",
"source" : "KIOSK",
"deviceUuid" : "uniquedeviceuuid"
}
});
assert.isNotNull(result);
assert.property(result, 'token');
var auth_token=result.token;
console.log(auth_token)
}).timeout(15000);
it('should return token for authorized user', async () => {
const result = await request({
headers: Object.assign(config.headers, { 'Authorization': 'Bearer '+auth_token }),
url: `${config.url}/rest/v1/auth/with-password`,
method: "POST",
json: {
"email" : "dulexun3hvw0@10minut.xyz",
"password" : "Test123"
}
});
assert.isNotNull(result);
assert.property(result, 'token');
assert.property(result, 'user');
console.log('token:', result.token);
}).timeout(15000);
});
in further test i want to pass Bearer token to Authorization field in diffrent class config.js
config.headers = {
'User-Agent': 'WOR API Tester', // android
Source: 'MOBILE',
'Accept-Language': 'EN',
Authorization:'Bearer '+auth_token;
};
module.exports = config;
Aucun commentaire:
Enregistrer un commentaire