Replies: 2 comments 6 replies
-
Try invoking the const { spec, request } = require('pactum');
const { Given, When, Then, Before } = require('@cucumber/cucumber');
Before(async () => {
await spec()
.post('/credentials')
.withForm({
username: email,
password: passw,
})
.expectStatus(200)
.stores('token', 'access_token');
request.setDefaultHeaders('Authorization', 'Bearer $S{token}');
}); |
Beta Was this translation helpful? Give feedback.
5 replies
-
Below is the test code... beforeAll(async () => {
await pactum
.spec()
.post('/auth/signin')
.withBody(dtoLogin)
.expectStatus(200)
.stores('userAt', 'access_token');
pactum.request.setDefaultHeaders(
'Authorization',
`Bearer $S{userAt}`,
);
console.log('pactum store done in before');
});
describe('Get me', () => {
it('should get current user', () => {
return pactum
.spec()
.get('/user/me')
.inspect()
.expectStatus(200);
});
}); Login request output is Below is console log
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to store the access token to use this value later. I have :
syntax '$S{token}' is a string, the next request is with "headers": {
"Authorization": "Bearer $S{token}"
},
what am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions