Pregunta

How can I create multiple cookies with a single file? All I have to just do is, merge these two file into one single file, to test it for both - valid and invalid cookie. How can I achieve this?

First file:

valid cookie valid_spec.js

 var frisby = require('./lib/frisby');
 // Global setup for all tests
 frisby.globalSetup({
 request: {
 headers:{'Accept': 'application/json,  application/x-httpd-php', 'Cookie': 'authenticationToken=5363; activationID=1'}
 },
  timeout: (30 * 1000)
});


/**
* Tests -> GET
*/
frisby.create(' ')
.get('http://xyz/auto?limit=0')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('status',{
 message: "SUCCESS",
 code: 1
 })
.toss(); 

Second file:

INVALID cookie invalid_spec.js

var frisby = require('./lib/frisby');

// Global setup for all tests
 frisby.globalSetup({
 request: {
 headers:{'Accept': 'application/json,  application/x-httpd-php', 'Cookie': 'authenticationToken=5363; activationID=11123fgf'}
 },
 timeout: (30 * 1000)
 });


/**
* Tests -> GET
*/
frisby.create(' ')
.get('http://xyz/auto?limit=0')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('status',{
message: "DATABASE_ERROR",
code: 2
 })
 .toss(); 
¿Fue útil?

Solución

You need to call the second test from an after callback.

like so:

var frisby = require('./lib/frisby');

frisby.globalSetup({
    request: {
        headers: {
            'Accept': 'application/json,  application/x-httpd-php',
            'Cookie': 'authenticationToken=5363; activationID=1'
        }
    },
    timeout: (30 * 1000)
});


frisby.create(' ')
    .get('http://xyz/auto?limit=0')
    .expectStatus(200)
    .expectHeaderContains('content-type', 'application/json')
    .expectJSON('status', {
        message: "SUCCESS",
        code: 1
    })
    .after(function() {

        frisby.create(' ')
            .get('http://xyz/auto?limit=0')
            .expectStatus(200)
            .expectHeaderContains('content-type', 'application/json')
            .expectJSON('status', {
                message: "DATABASE_ERROR",
                code: 2
            })
            .toss();

    })
    .toss();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top