Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

.idea
node_modules
12 changes: 6 additions & 6 deletions __pact-tests__/user_api.test.pact.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { like, eachLike } = Matchers;
describe('user management request', () => {
// const urlpath = '/api/uaa/admin/users?username=mike&firstName=mike&lastName=tan&password=CukeStudio)123&email=mike@amazon.com&organizations=e290e5c2-bd43-11ea-882a-cd26553a22fa&role=ROLE_KCP_DUMMY'
const urlpath = '/api/uaa/admin/users'

const getApiEndpoint = () => `http://${global.host}:${global.port}`
/*
** POST /api/uaa/admin/users?username=mike&firstName=mike&lastName=tan&password=CukeStudio)123&email=mike@amazon.com&organizations=e290e5c2-bd43-11ea-882a-cd26553a22fa&role=ROLE_KCP_DUMMY'
Expand All @@ -27,14 +27,14 @@ describe('user management request', () => {
roles: [],
organizations: [{uuid: "e290e5c2-bd43-11ea-882a-cd26553a22fa", code: "ABC"}]
};


const HEADER = {
'Content-Type': 'application/json',
// 'Authorization': like("Bearer eyJzdWIiOiI1ZWU4MT")
'Authorization': like("Bearer eyJzdWIiOiI1ZWU4MT")
};


const BODY = EXPECTED_BODY;

beforeEach(() => {
Expand All @@ -57,7 +57,7 @@ describe('user management request', () => {
});

// add expectations
it('returns a successfully body', () => {
it('returns a successfully body', () => {
return axios.request({
method: 'POST',
baseURL: getApiEndpoint(),
Expand Down
153 changes: 153 additions & 0 deletions logs/pact.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
I, [2020-07-20T12:19:30.937046 #1459] INFO -- : Registered expected interaction POST /api/uaa/admin/users
D, [2020-07-20T12:19:30.937368 #1459] DEBUG -- : {
"description": "uuid and username",
"providerState": "Create a new user",
"request": {
"method": "POST",
"path": "/api/uaa/admin/users",
"headers": {
"Content-Type": "application/json",
"Authorization": {
"json_class": "Pact::SomethingLike",
"contents": "Bearer eyJzdWIiOiI1ZWU4MT"
}
},
"body": {
"json_class": "Pact::SomethingLike",
"contents": {
"uuid": "60b7a577-c623-4c03-a902-aa3200bb0e89",
"email": "mike@amazon.com",
"username": "mike",
"firstName": "mike",
"lastName": "tan",
"title": null,
"department": null,
"location": null,
"groups": [

],
"roles": [

],
"organizations": [
{
"uuid": "e290e5c2-bd43-11ea-882a-cd26553a22fa",
"code": "ABC"
}
]
}
}
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json",
"Authorization": {
"json_class": "Pact::SomethingLike",
"contents": "Bearer eyJzdWIiOiI1ZWU4MT"
}
},
"body": {
"json_class": "Pact::SomethingLike",
"contents": {
"uuid": "60b7a577-c623-4c03-a902-aa3200bb0e89",
"email": "mike@amazon.com",
"username": "mike",
"firstName": "mike",
"lastName": "tan",
"title": null,
"department": null,
"location": null,
"groups": [

],
"roles": [

],
"organizations": [
{
"uuid": "e290e5c2-bd43-11ea-882a-cd26553a22fa",
"code": "ABC"
}
]
}
}
}
}
I, [2020-07-20T12:19:30.945050 #1459] INFO -- : Received request POST /api/uaa/admin/users
D, [2020-07-20T12:19:30.945184 #1459] DEBUG -- : {
"path": "/api/uaa/admin/users",
"query": "",
"method": "post",
"body": {
"uuid": "60b7a577-c623-4c03-a902-aa3200bb0e89",
"email": "mike@amazon.com",
"username": "mike",
"firstName": "mike",
"lastName": "tan",
"title": null,
"department": null,
"location": null,
"groups": [

],
"roles": [

],
"organizations": [
{
"uuid": "e290e5c2-bd43-11ea-882a-cd26553a22fa",
"code": "ABC"
}
]
},
"headers": {
"Content-Length": "276",
"Content-Type": "application/json",
"Accept": "application/json, text/plain, */*",
"Authorization": "[object Object]",
"User-Agent": "axios/0.19.0",
"Host": "127.0.0.1:8991",
"Connection": "close",
"Version": "HTTP/1.1"
}
}
I, [2020-07-20T12:19:30.945664 #1459] INFO -- : Found matching response for POST /api/uaa/admin/users
D, [2020-07-20T12:19:30.945812 #1459] DEBUG -- : {
"status": 201,
"headers": {
"Content-Type": "application/json",
"Authorization": {
"json_class": "Pact::SomethingLike",
"contents": "Bearer eyJzdWIiOiI1ZWU4MT"
}
},
"body": {
"json_class": "Pact::SomethingLike",
"contents": {
"uuid": "60b7a577-c623-4c03-a902-aa3200bb0e89",
"email": "mike@amazon.com",
"username": "mike",
"firstName": "mike",
"lastName": "tan",
"title": null,
"department": null,
"location": null,
"groups": [

],
"roles": [

],
"organizations": [
{
"uuid": "e290e5c2-bd43-11ea-882a-cd26553a22fa",
"code": "ABC"
}
]
}
}
}
I, [2020-07-20T12:19:30.952366 #1459] INFO -- : Verifying - interactions matched
I, [2020-07-20T12:19:30.955772 #1459] INFO -- : Cleared interactions
I, [2020-07-20T12:19:30.959902 #1459] INFO -- : Updating pact for iProvider at /Users/budi.injo/Documents/work/TL/github/pact-demo-js/pacts/iconsumer-iprovider.json
2 changes: 1 addition & 1 deletion pactTestWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

beforeAll(() => provider.setup())

afterAll(() => provider.finalize())
afterAll(() => provider.finalize())
95 changes: 95 additions & 0 deletions pacts/iconsumer-iprovider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"consumer": {
"name": "iConsumer"
},
"provider": {
"name": "iProvider"
},
"interactions": [
{
"description": "uuid and username",
"providerState": "Create a new user",
"request": {
"method": "POST",
"path": "/api/uaa/admin/users",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer eyJzdWIiOiI1ZWU4MT"
},
"body": {
"uuid": "60b7a577-c623-4c03-a902-aa3200bb0e89",
"email": "mike@amazon.com",
"username": "mike",
"firstName": "mike",
"lastName": "tan",
"title": null,
"department": null,
"location": null,
"groups": [

],
"roles": [

],
"organizations": [
{
"uuid": "e290e5c2-bd43-11ea-882a-cd26553a22fa",
"code": "ABC"
}
]
},
"matchingRules": {
"$.headers.Authorization": {
"match": "type"
},
"$.body": {
"match": "type"
}
}
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer eyJzdWIiOiI1ZWU4MT"
},
"body": {
"uuid": "60b7a577-c623-4c03-a902-aa3200bb0e89",
"email": "mike@amazon.com",
"username": "mike",
"firstName": "mike",
"lastName": "tan",
"title": null,
"department": null,
"location": null,
"groups": [

],
"roles": [

],
"organizations": [
{
"uuid": "e290e5c2-bd43-11ea-882a-cd26553a22fa",
"code": "ABC"
}
]
},
"matchingRules": {
"$.headers.Authorization": {
"match": "type"
},
"$.body": {
"match": "type"
}
}
},
"metadata": null
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
25 changes: 8 additions & 17 deletions provider/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@ server.use(
)

server.use((req, res, next) => {
res.header("Content-Type", "application/json")
next()
})

/*
server.use((req, res, next) => {

const token = req.headers["authorization"]
const token = req.headers["authorization"]
if (token !== "Bearer eyJzdWIiOiI1ZWU4MT") {
res.sendStatus(401).send()
} else {
next()
}

next()
})
*/


const userRepository = new Repository()

Expand All @@ -55,16 +46,16 @@ server.post("/api/uaa/admin/users", (req, res) => {
return
}

console.log('REQ BODY: ' + JSON.stringify(req.body));
const authorizationToken = req.headers["authorization"]

res.setHeader('Content-Type', 'application/json');
res.sendStatus(201).send(JSON.stringify(req.body))

//userRepository.insert(user)
//res.json(user)
res.setHeader('Authorization', authorizationToken);
res.writeHead(201)
res.end(JSON.stringify(user));
})

module.exports = {
server,
importData,
userRepository,
}
}
8 changes: 1 addition & 7 deletions provider/verify.pact.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { server, importData, userRepository } = require('./provider');

const port = process.env.PORT || 8082;


beforeEach((done) => {
server.listen(port, (err) => {
if (err) return done(err);
Expand All @@ -13,10 +12,6 @@ beforeEach((done) => {
})
});

afterEach((done) => {
return server;
});

describe('Pact Verification', () => {
test('should validate the expectations of our consumer', (done) => {
let token = "INVALID TOKEN"
Expand Down Expand Up @@ -54,8 +49,7 @@ describe('Pact Verification', () => {
},
},
}



return new Verifier(opts).verifyProvider().then(output => {
console.log("Pact Verification Complete!")
console.log(output)
Expand Down