Skip to content

Instantly share code, notes, and snippets.

@tshortt
Last active September 21, 2016 15:42
Show Gist options
  • Save tshortt/e453cf12ea7c3114f0c166dc9e75bdfa to your computer and use it in GitHub Desktop.
Save tshortt/e453cf12ea7c3114f0c166dc9e75bdfa to your computer and use it in GitHub Desktop.
Two Pact interactions, one with, one without query string
/*eslint-disable*/
(function(Pact) {
describe('Client', function() {
var client, projectsProvider;
beforeAll(function(done) {
client = example.createClient('http://localhost:1234'); //jshint ignore:line
projectsProvider = Pact({ //jshint ignore:line
consumer: 'Employee Records',
provider: 'Employee'
});
// required for slower Travis CI environment
setTimeout(function() {
done();
}, 2000);
});
afterAll(function(done) {
projectsProvider.finalize()
.then(function() {
done();
}, function(err) {
done.fail(err);
});
});
describe('employee', function() {
beforeEach(function(done) {
projectsProvider.addInteraction({
uponReceiving: 'a request for employee',
withRequest: {
method: 'get',
path: '/EmployeeApi/api/organizations/0/employees'
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: {
'data': [{
'id': '0',
'type': 'employees'
}]
}
}
})
.then(function() {
done();
}, function(err) {
done.fail(err);
});
});
it('should respond with proper schema', function(done) {
//Run the tests
client.employee()
.then(projectsProvider.verify)
.then(function(response) {
// var resp = JSON.parse(response);
done();
})
.catch(function(err) {
done.fail(err);
});
});
});
describe('employees with email', function() {
beforeEach(function(done) {
projectsProvider.addInteraction({
uponReceiving: 'a request for employee with email',
withRequest: {
method: 'get',
path: '/EmployeeApi/api/organizations/0/employees',
query: {
'include': 'emails'
}
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: {
'data': [{
'id': '0',
'type': 'employees',
'email': 'employee@foo.com'
}]
}
}
})
.then(function() {
done();
}, function(err) {
done.fail(err);
});
});
it('should respond with proper schema', function(done) {
//Run the tests
client.employeesWithEmails()
.then(projectsProvider.verify)
.then(function(response) {
// var resp = JSON.parse(response);
// expect(resp.data[0].attributes.firstName).toEqual('firstName');
done();
})
.catch(function(err) {
done.fail(err);
});
});
});
});
})(Pact);
@tshortt
Copy link
Author

tshortt commented Sep 21, 2016


I, [2016-09-21T11:39:29.918588 #95051]  INFO -- : Registered expected interaction GET /EmployeeApi/api/organizations/0/employees
D, [2016-09-21T11:39:29.918985 #95051] DEBUG -- : {
  "description": "a request for employee",
  "request": {
    "method": "GET",
    "path": "/EmployeeApi/api/organizations/0/employees"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json; charset=utf-8"
    },
    "body": {
      "data": [
        {
          "id": "0",
          "type": "employees"
        }
      ]
    }
  }
}
I, [2016-09-21T11:39:29.923683 #95051]  INFO -- : Received request GET /EmployeeApi/api/organizations/0/employees
D, [2016-09-21T11:39:29.923788 #95051] DEBUG -- : {
  "path": "/EmployeeApi/api/organizations/0/employees",
  "query": "",
  "method": "get",
  "headers": {
    "Accept": "application/json",
    "Referer": "http://localhost:9876/context.html",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
I, [2016-09-21T11:39:29.924114 #95051]  INFO -- : Found matching response for GET /EmployeeApi/api/organizations/0/employees
D, [2016-09-21T11:39:29.924383 #95051] DEBUG -- : {
  "status": 200,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": {
    "data": [
      {
        "id": "0",
        "type": "employees"
      }
    ]
  }
}
I, [2016-09-21T11:39:29.927834 #95051]  INFO -- : Verifying - interactions matched for example ""
I, [2016-09-21T11:39:29.933137 #95051]  INFO -- : Registered expected interaction GET /EmployeeApi/api/organizations/0/employees?include=emails
D, [2016-09-21T11:39:29.933462 #95051] DEBUG -- : {
  "description": "a request for employee with email",
  "request": {
    "method": "GET",
    "path": "/EmployeeApi/api/organizations/0/employees",
    "query": {
      "include": [
        "emails"
      ]
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json; charset=utf-8"
    },
    "body": {
      "data": [
        {
          "id": "0",
          "type": "employees"
        }
      ],
      "included": [
        {
          "id": "0",
          "type": "emails",
          "links": {
            "self": "http://api.frontlineeducation.com/EmployeeApi/api/employees/0/emails/0"
          }
        }
      ]
    }
  }
}
I, [2016-09-21T11:39:29.936934 #95051]  INFO -- : Received request GET /EmployeeApi/api/organizations/0/employees?include=emails
D, [2016-09-21T11:39:29.937023 #95051] DEBUG -- : {
  "path": "/EmployeeApi/api/organizations/0/employees",
  "query": "include=emails",
  "method": "get",
  "headers": {
    "Accept": "application/json",
    "Referer": "http://localhost:9876/context.html",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
E, [2016-09-21T11:39:29.937207 #95051] ERROR -- : Multiple interactions found for GET /EmployeeApi/api/organizations/0/employees?include=emails:
D, [2016-09-21T11:39:29.937587 #95051] DEBUG -- : {
  "description": "a request for employee",
  "request": {
    "method": "GET",
    "path": "/EmployeeApi/api/organizations/0/employees"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json; charset=utf-8"
    },
    "body": {
      "data": [
        {
          "id": "0",
          "type": "employees",
        }
      ]
    }
  }
}
D, [2016-09-21T11:39:29.937959 #95051] DEBUG -- : {
  "description": "a request for employee with email",
  "request": {
    "method": "GET",
    "path": "/EmployeeApi/api/organizations/0/employees",
    "query": {
      "include": [
        "emails"
      ]
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json; charset=utf-8"
    },
    "body": {
      "data": [
        {
          "id": "0",
          "type": "employees"
        }
      ],
      "included": [
        {
          "id": "0",
          "type": "emails",
          "attributes": {
            "emailType": 0,
            "isPrimary": true,
            "emailAddress": "a@aol.com",
            "ownerVersionNumber": 0,
            "ownerId": null
          },
          "links": {
            "self": "http://api.frontlineeducation.com/EmployeeApi/api/employees/0/emails/0"
          }
        }
      ]
    }
  }
}
W, [2016-09-21T11:39:29.940550 #95051]  WARN -- : Verifying - actual interactions do not match expected interactions for example "". 
Missing requests:
    GET /EmployeeApi/api/organizations/0/employees?include=emails


W, [2016-09-21T11:39:29.940581 #95051]  WARN -- : Missing requests:
    GET /EmployeeApi/api/organizations/0/employees?include=emails


I, [2016-09-21T11:39:29.944659 #95051]  INFO -- : Writing pact with details {:consumer=>{:name=>"Employee Records"}, :provider=>{:name=>"Employee"}}
I, [2016-09-21T11:39:29.944729 #95051]  INFO -- : Writing pact for Employee to /Users/tshortt/projects/Util-UISuperSuit/api-tests/pacts/employee_records-employee.json
I, [2016-09-21T11:39:29.947984 #95051]  INFO -- : Cleared interactions before example ""


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment