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

testing different params for testing similar response #40

Open
thevikas opened this issue Nov 30, 2018 · 4 comments
Open

testing different params for testing similar response #40

thevikas opened this issue Nov 30, 2018 · 4 comments

Comments

@thevikas
Copy link

I wish to test few errors and all these errors result in same http response code.
I'm using hooks and can't get it to run second time.
For e.g. 403 is returned for many reasons. I want to test two and dredd only runs for first test and forgets other.
Please help.

@ddelnano
Copy link
Owner

ddelnano commented Dec 1, 2018

Can you post some code examples. It’s very difficult for me to help without that.

@thevikas
Copy link
Author

thevikas commented Dec 1, 2018

For example the following hook is written twice because I want to test same 403 response for two different requests.

Hooks::before("sites > /api/sites/{id}.json > submits changes to existing site > 403 > application/json; charset=utf-8", function(&$transaction) 
{
//calls with wrong ID
$transaction->skip = false;
$transaction->fullPath = $transaction->request->uri = '/api/sites/21999.json?token=' . 'goodtoken';
    
}

Hooks::before("sites > /api/sites/{id}.json > submits changes to existing site > 403 > application/json; charset=utf-8", function(&$transaction) 
{
//calls with validation errors
$transaction->skip = false;
$transaction->fullPath = $transaction->request->uri = '/api/sites/21.json?token=' . 'goodtoken';
}

Only the first API call is made. The second one does not. Even though the hook itself is called but not the API.

@lulco
Copy link

lulco commented Feb 15, 2019

Hi @thevikas for this purpose, I use this hack, hope it will help you:

use Dredd\Hooks;

Hooks::beforeAll(function(&$transactions) {
    $newTransactions = [];
    foreach ($transactions as $transaction) {
        if (strpos($transaction->name, ' > 403 > ') !== false) {
            // for all > 403 > paths create two new transactions, one skip second fail
            $newTransaction = clone $transaction;
            $newTransaction->skip = true;
            $newTransactions[] = $newTransaction;

            $newTransaction = clone $transaction;
            $newTransaction->fail = true;
            $newTransactions[] = $newTransaction;
        } else {
            // just copy other transactions
            $newTransactions[] = $transaction;
        }
    }
    $transactions = $newTransactions;
});

@lulco
Copy link

lulco commented Feb 16, 2019

I found out that clone not working here, I used another hack unserialize(serialize($transaction)); and now it works (I hope :))

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

3 participants