Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use rewrite feature properly? #199

Open
alexnot95 opened this issue Nov 17, 2023 · 2 comments
Open

How to use rewrite feature properly? #199

alexnot95 opened this issue Nov 17, 2023 · 2 comments

Comments

@alexnot95
Copy link

alexnot95 commented Nov 17, 2023

For now we are using SBUITestTunnel with stubRequest() mainly, but I have a case where I need to rewrite a response.

For example: I have endpoint which will return user properties: POST /user/signin

and in response I will have a structure something like this:

{
  "user_properties": {
    "name": "test",
    "age": 21,
    "gender": "female"
  },
  "data": {
    "expires_in": 18800
}

I need rewrite expires_in field in response it should be for example 5 instead of 18800 but nothing changes...

also I tries to rewrite name field with other name but it also didn't change, however stub feature works as expected if I want to simulate 500 status code on this request everything works, so library works as expected but I can't userstand how to properly use rewrite feature.

How I tried to do it:

let match = SBTRequestMatch(url: "/user/signin", method: "POST")
let rewrite = SBTRewrite(responseReplacement: [SBTRewriteReplacement(find: "18800", replace: "5")])
app.rewriteRequests(matching: match, rewrite: rewrite)
let match = SBTRequestMatch(url: "/user/signin", method: "POST")
let rewrite = SBTRewrite(responseReplacement: [SBTRewriteReplacement(find: "test", replace: "new_test")])
app.rewriteRequests(matching: match, rewrite: rewrite)

and this stub works as expected:

let match = SBTRequestMatch(url: "/user/signin", method: "POST")
let response = SBTStubResponse(returnCode: 500)
app.stubRequests(matching: match, response: response)
@alexnot95 alexnot95 changed the title How to user rewrite feature properly? How to use rewrite feature properly? Nov 17, 2023
@tcamin
Copy link
Member

tcamin commented Nov 20, 2023

The RewriteTests.swift contains rewriting tests. Could you check if using requestReplacement instead of responseReplacement works?

@alexnot95
Copy link
Author

Looks like requestReplacement doesn't work too :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants