Comments (21)
Frisby tests cannot be run sequentially, and your test suite should never depend on the order of tests that are run.
If there is setup you need to do for each successive test in your suite, you have a few options. You can use frisby.use(withTokenAuth).get(...).expect(...)
in each test you need it in. Your withTokenAuth
function might look like this:
// Define your helper function
function withTokenAuth(spec) {
const token = '123abc';
return spec.setup({
request: {
headers: {
'Authorization': 'Bearer ' +token,
'header':'value'
}
}
});
}
it('make call USING GLOBAL SETUP' , function() {
console.log('########### In IT call ###########')
return frisby
.use(withTokenAuth) // USE the `withTokenAuth` function here in your test (and in every test you need it in)
.post('url/call',
{
// json body
})
.expect('status', 200);
});
You can also just use the setup
method directly in each test as well.
from frisby.
Thanks @vlucas .
cant I run my tests sequentially using JEST -i option with it.
What if need to use globalSetup as a funtion in one of the helpers file and the use token from function in my test in different file.
Will it work. Please suggest.
from frisby.
- It looks like you haven't set
token
in firstit
block. -i
option is enabled in case of multiple test files injest
.
from frisby.
@vlucas Thanks for your response.
with your solution I am trying little variation like..
Now when I call postCall(url,body) passing all required parameters in my spec file I am getting
from frisby.
@vlucas can you please provide your input on this.
thanks in advance
from frisby.
HTTP status 415
has wrong Content-Type
.
What is Content-Type
of request set to ?
Have you changed Content-Type
in globalSetup
?
from frisby.
@vlucas when I am passing token as the hard coded value and calling postCall (url,body) with .inspectRequestHeaders() it works and shows me correct headers getting passed
from frisby.
Is there issues with getToken()
?
from frisby.
@vlucas can you please provide you thought on this.
thanks in advance
from frisby.
@H1Gdev if you check my comment above getToken() works fine and returns me token.
from frisby.
Can you dump the request headers so we can see what is actually being sent? 415 is a response from your server, and we cannot debug that or provide support for it.
Also:
return spec.setup({
request: {
headers: {
'Authorization': 'Bearer ' +token,
'header':'value' // Did you remember to delete this line? This was just an example...
}
}
});
from frisby.
@vlucas thanks for response
For token creation function I am using these set of headers
'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),
'ouc_header':'admin',
'Content-Type': 'application/scim+json'
token from above I use in below
and for method withTokenAuth() these are header that are required
'Authorization': Bearer TOKEN,
'ouc_header':'non_admin',
'Content-Type': 'application/scim+json'
NOTE:
When I call these method independently it works fine.
from frisby.
When I call these method independently it works fine.
Please paste each code.
from frisby.
@H1Gdev @vlucas Please find code snippet I am using.
function getToken(url){
return frisby
.setup({
request:{
headers:
{
'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),
'ouc_header':'admin',
'Content-Type': 'application/scim+json'
},
}
})
//body : this method works fine
});
});
**============= new file where I am calling getToken() to get my token.**
function withTokenAuth1(spec) {
`const instance_token= getToken(url);
return spec.setup({
request: {
headers:
{
'Authorization': 'Bearer '+instance_token,
'ouc_header':'non_admin',
'Content-Type': 'application/scim+json'
}
}
});
}
function postCalltest()(){
return frisby
.use(withTokenAuth1)
//body
})
}
//
now I am calling this postCalltest()() in my spec ...and then getToken() returns me token as console show it.
After that I am getting this.
Request Headers:
Content-Type: application/scim+json
User-Agent: frisby/2.1.2 (+https://github.com/vlucas/frisby)
Authorization: Basic jhkjhkhkhkk=
ouc_header: admin
//header from getToken method
FAILURE Status: 401
JSON: {
"response": [ //this is from withTokenAuth1() as i am calling it in postCalltest()()
"value:Error"
],
"status": 401,
"scimType": "invalidValue",
"detail": "Attribute \"ouc_header\" is required." //not sure why it is not able to set header here for token and ouc_header
}
F*
Failures:
1) Token Suite Add operation
Message:
AssertionError: HTTP status 200 !== 415
I am not sure why it is not able to set header in withTokenAuth1() for ouc_header or token
from frisby.
We cannot debug your server response for you. This is not a free support forum.
I am closing this issue for now.
You can re-open it If you can give us code for both server and client in an isolated and reproducible way that proves the issue with the Frisby library itself, then we can help with a fix. Otherwise, we cannot spend any more time on this issue.
from frisby.
I can't understand this code:confused:
At the very least, make code that completes frisby
.
(For example, list tests that pass and fail.)
from frisby.
@H1Gdev @vlucas
you can close this this ticket if you want...but could not understand what you can not get of code snippet.
It clearly shows like headers handling is an issue when it getting passed from getToken(url) [this method returns token from body reponse.] to withTokenAuth1().
Now withTokenAuth1() method setups the header to be used for different rest method ie. postCalltest().
Well if you dont want to debug thats okay.
thanks for your time.
from frisby.
getToken(url) [this method returns token from body reponse.]
getToken(url)
returns frisby
(that is, Promise).
I don't know how to give advice because the code is incomplete like this...
So if you want to reopen it, write some code that works correctly.
from frisby.
@H1Gdev check this code sinppet for getToken(url)
getToken(URL){
return frisby
.setup
({
request:
{
headers:
{
'Authorization': 'Basic ' + Buffer.from("usrname:pwd").toString('base64'),
'ouc_header':'admin',
'Content-Type': 'application/scim+json'
}
}
})
.get(apiURL)
.inspectResponse()
.inspectRequestHeaders()
.expect('status', 200)
.then(res => {
var token=res._token;
console.log(token);
});
}
is it now clear ???
from frisby.
We need both the client and server code to help you. We need an independent code repository that we can clone and run that has both the server and frisby tests for it.
One test that shows where it is working.
One test that shows where it is not.
You have all the code and the full context so it might be clear to you, but it is not clear at all to us. We need something isolated and reproducible in order to help you.
from frisby.
It's no good returning Promise
.
If you use async
and await
like below, you will get the expected behavior.
async function getToken(URL) {
return frisby
.setup
({
request:
{
headers:
{
'Authorization': 'Basic ' + Buffer.from("usrname:pwd").toString('base64'),
'ouc_header':'admin',
'Content-Type': 'application/scim+json'
}
}
})
.get(apiURL)
.inspectResponse()
.inspectRequestHeaders()
.expect('status', 200)
.then(res => {
var token=res._token; // Can you really get it with this ???
console.log(token);
return token;
});
}
const instance_token= await getToken(url);
But first, it's better to understand Promise of JavaScript.
from frisby.
Related Issues (20)
- Iterate through multiple get calls. HOT 3
- Could not generate token using frisby v2 HOT 10
- frsiby method call returns _fetch: Promise { <pending> }
- could not run test
- unexpected response when posting request with content type x-www-form-urlencoded HOT 9
- Does not show the line where code is failing. Its always points the frisby code.
- Upgrade Joi dependency to v17 HOT 1
- Missing logo HOT 3
- What's the appropriate way to trigger CI/CD? Using a web server? HOT 1
- Is there a function similar to bodyContains but for headers? HOT 2
- Loop through JSON object in Expect()? HOT 12
- Using query parameters in API calls HOT 1
- PUT Call Double Encoding URL HOT 3
- Remove Joi export and move it from peer dependencies to dependencies
- Latest joi version does not work HOT 3
- Unhandled promise rejection: TypeError: response.textConverted is not a function while using Jasmine with Frisby HOT 1
- Update npm package.
- Socket hang up / ECONNRESET errors with Node.js 20.x HOT 4
- CVE on frisby dependency (joi)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frisby.