Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit fd86e47

Browse files
authored
Merge branch 'master' into add_label_schema_0
2 parents 678a359 + 0863fe5 commit fd86e47

File tree

12 files changed

+389
-58
lines changed

12 files changed

+389
-58
lines changed

.travis.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ jdk:
77
install: true
88

99
env:
10-
- GROUP=weaveworksdemos COMMIT=$TRAVIS_COMMIT TAG=$TRAVIS_TAG;
10+
- GROUP=weaveworksdemos COMMIT=$TRAVIS_COMMIT TAG=$TRAVIS_TAG REPO=cart;
1111

1212
script:
1313
- set -e
14-
- ./scripts/build.sh;
14+
- travis_wait ./scripts/build.sh;
1515
- ./test/test.sh unit.py
1616
- ./test/test.sh component.py
17-
# - ./test/test.sh container.py --tag $TAG
17+
- ./test/test.sh container.py --tag $TAG
1818

1919
after_success:
2020
- set -e;
@@ -25,3 +25,20 @@ after_success:
2525
fi;
2626
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS;
2727
- ./scripts/push.sh
28+
29+
before_install:
30+
- openssl aes-256-cbc -K $encrypted_71d9c8a3a58a_key -iv $encrypted_71d9c8a3a58a_iv
31+
-in cart_deploy_rsa.enc -out cart_deploy_rsa -d
32+
before_deploy:
33+
- eval "$(ssh-agent -s)"
34+
- chmod 600 $TRAVIS_BUILD_DIR/${REPO}_deploy_rsa
35+
- ssh-add $TRAVIS_BUILD_DIR/${REPO}_deploy_rsa
36+
addons:
37+
ssh_known_hosts: $BASTION
38+
deploy:
39+
provider: script
40+
skip_cleanup: true
41+
# The deploy.sh file actually points to the deploy file on the bastion. Not one in the repo.
42+
script: ssh -o StrictHostKeyChecking=no $BASTION_USER@$BASTION ./deploy.sh ${REPO} $COMMIT
43+
on:
44+
branch: master

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Build Status](https://travis-ci.org/microservices-demo/carts.svg?branch=master)](https://travis-ci.org/microservices-demo/carts) [![Coverage Status](https://coveralls.io/repos/github/microservices-demo/carts/badge.svg?branch=master)](https://coveralls.io/github/microservices-demo/carts?branch=master)
2+
[![](https://images.microbadger.com/badges/image/weaveworksdemos/cart.svg)](http://microbadger.com/images/weaveworksdemos/cart "Get your own image badge on microbadger.com")
23
# cart
34
A microservices-demo service that provides shopping carts for users.
45

api-spec/cart.json

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"version": "",
5+
"title": "Carts and items",
6+
"description": "Carts and items resources",
7+
"license": {
8+
"name": "MIT",
9+
"url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
10+
}
11+
},
12+
"host": "carts",
13+
"basePath": "/",
14+
"securityDefinitions": {},
15+
"schemes": [
16+
"http"
17+
],
18+
"consumes": [
19+
"application/json;charset=UTF-8",
20+
"text/plain"
21+
],
22+
"produces": [
23+
"application/json;charset=UTF-8",
24+
"text/plain"
25+
26+
],
27+
"paths": {
28+
"/carts/{customerId}": {
29+
"get": {
30+
"description": "",
31+
"operationId": "Get cart",
32+
"produces": [
33+
"application/json;charset=UTF-8"
34+
],
35+
"parameters": [
36+
{
37+
"name": "customerId",
38+
"in": "path",
39+
"required": true,
40+
"type": "string",
41+
"x-example": "1"
42+
}
43+
],
44+
"responses": {
45+
"200": {
46+
"description": "Returns cart",
47+
"schema": {
48+
"$ref": "#/definitions/Getcartresponse"
49+
}
50+
}
51+
}
52+
},
53+
"delete": {
54+
"description": "",
55+
"operationId": "Delete cart",
56+
"produces": [
57+
"application/json;charset=UTF-8"
58+
],
59+
"parameters": [
60+
{
61+
"name": "customerId",
62+
"in": "path",
63+
"required": true,
64+
"type": "string",
65+
"x-example": "1"
66+
}
67+
],
68+
"responses": {
69+
"202": {
70+
"description": ""
71+
}
72+
}
73+
}
74+
},
75+
"/carts/{customerId}/items": {
76+
"post": {
77+
"description": "",
78+
"operationId": "Add an item to the cart",
79+
"produces": [
80+
"application/json;charset=UTF-8"
81+
],
82+
"parameters": [
83+
{
84+
"name": "customerId",
85+
"in": "path",
86+
"required": true,
87+
"type": "string",
88+
"x-example": "579f21ae98684924944651bf"
89+
},
90+
{
91+
"name": "body",
92+
"in": "body",
93+
"required": true,
94+
"schema": {
95+
"$ref": "#/definitions/CartItem",
96+
"example": {
97+
"itemId":"819e1fbf-8b7e-4f6d-811f-693534916a8b",
98+
"quantity": 20,
99+
"unitPrice" : 99.0
100+
}
101+
}
102+
}
103+
],
104+
"responses": {
105+
"201": {
106+
"description": "",
107+
"schema": {
108+
"$ref": "#/definitions/CartItem"
109+
}
110+
}
111+
}
112+
},
113+
"patch": {
114+
"description": "Update an item",
115+
"operationId": "Update item",
116+
"produces": [
117+
"application/json;charset=UTF-8"
118+
],
119+
"parameters": [
120+
{
121+
"name": "customerId",
122+
"in": "path",
123+
"required": true,
124+
"type": "string",
125+
"x-example": "579f21ae98684924944651bf"
126+
},
127+
{
128+
"name": "body",
129+
"in": "body",
130+
"required": true,
131+
"schema": {
132+
"type": "object"
133+
}
134+
}
135+
],
136+
"responses": {
137+
"200": {
138+
"description": ""
139+
}
140+
}
141+
}
142+
},
143+
"/carts/{customerId}/items/{itemId}": {
144+
"delete": {
145+
"description": "Delete cart item",
146+
"operationId": "delete",
147+
148+
"parameters": [
149+
{
150+
"name": "itemId",
151+
"in": "path",
152+
"required": true,
153+
"type": "string",
154+
"x-example": "819e1fbf-8b7e-4f6d-811f-693534916a8b"
155+
},
156+
{
157+
"name": "customerId",
158+
"in": "path",
159+
"required": true,
160+
"type": "string",
161+
"x-example": "579f21ae98684924944651bf"
162+
}
163+
],
164+
"responses": {
165+
"202": {
166+
"description": "Delete response"
167+
}
168+
}
169+
}
170+
}
171+
},
172+
"definitions": {
173+
"Getcartresponse": {
174+
"title": "Get cart response",
175+
"type": "object",
176+
"properties": {
177+
"customerId": {
178+
"type": "string"
179+
}
180+
},
181+
"required": [
182+
"customerId"
183+
]
184+
},
185+
"CartItem": {
186+
"title": "Cart item",
187+
"type": "object",
188+
"properties": {
189+
"itemId": {
190+
"type": "string"
191+
},
192+
"quantity": {
193+
"type": "integer"
194+
},
195+
"unitPrice": {
196+
"type": "number"
197+
}
198+
},
199+
"required": [
200+
"itemId",
201+
"quantity",
202+
"unitPrice"
203+
]
204+
}
205+
}
206+
}

api-spec/hooks.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const hooks = require('hooks');
2+
const {MongoClient} = require('mongodb');
3+
const ObjectID = require('mongodb').ObjectID;
4+
5+
let db;
6+
7+
const address = [
8+
{"_id":ObjectID("579f21ae98684924944651bd"),"_class":"works.weave.socks.accounts.entities.Address","number":"69","street":"Wilson Street","city":"Hartlepool","postcode":"TS26 8JU","country":"United Kingdom"},
9+
{"_id":ObjectID("579f21ae98684924944651c0"),"_class":"works.weave.socks.accounts.entities.Address","number":"122","street":"Radstone WayNet","city":"Northampton","postcode":"NN2 8NT","country":"United Kingdom"},
10+
{"_id":ObjectID("579f21ae98684924944651c3"),"_class":"works.weave.socks.accounts.entities.Address","number":"3","street":"Radstone Way","city":"Northampton","postcode":"NN2 8NT","country":"United Kingdom"}
11+
];
12+
13+
14+
const card = [
15+
{"_id":ObjectID("579f21ae98684924944651be"),"_class":"works.weave.socks.accounts.entities.Card","longNum":"8575776807334952","expires":"08/19","ccv":"014"},
16+
{"_id":ObjectID("579f21ae98684924944651c1"),"_class":"works.weave.socks.accounts.entities.Card","longNum":"8918468841895184","expires":"08/19","ccv":"597"},
17+
{"_id":ObjectID("579f21ae98684924944651c4"),"_class":"works.weave.socks.accounts.entities.Card","longNum":"6426429851404909","expires":"08/19","ccv":"381"}
18+
];
19+
20+
const cart = [
21+
{"_id":ObjectID("579f21de98689ebf2bf1cd2f"),"_class":"works.weave.socks.cart.entities.Cart","customerId":"579f21ae98684924944651bf","items":[{"$ref":"item","$id":ObjectID("579f227698689ebf2bf1cd31")},{"$ref":"item","$id":ObjectID("579f22ac98689ebf2bf1cd32")}]},
22+
{"_id":ObjectID("579f21e298689ebf2bf1cd30"),"_class":"works.weave.socks.cart.entities.Cart","customerId":"579f21ae98684924944651bfaa","items":[]}
23+
];
24+
25+
26+
const item = [
27+
{"_id":ObjectID("579f227698689ebf2bf1cd31"),"_class":"works.weave.socks.cart.entities.Item","itemId":"819e1fbf-8b7e-4f6d-811f-693534916a8b","quantity":20,"unitPrice":99.0}
28+
];
29+
30+
31+
const customer = [
32+
{"_id":"579f21ae98684924944651bf","_class":"works.weave.socks.accounts.entities.Customer","firstName":"Eve","lastName":"Berger","username":"Eve_Berger","addresses":[{"$ref":"address","$id":ObjectID("579f21ae98684924944651bd")}],"cards":[{"$ref":"card","$id":ObjectID("579f21ae98684924944651be")}]
33+
},
34+
{"_id":"579f21ae98684924944651c2","_class":"works.weave.socks.accounts.entities.Customer","firstName":"User","lastName":"Name","username":"user","addresses":[{"$ref":"address","$id":ObjectID("579f21ae98684924944651c0")}],"cards":[{"$ref":"card","$id":ObjectID("579f21ae98684924944651c1")}]},
35+
{"_id":"579f21ae98684924944651c5","_class":"works.weave.socks.accounts.entities.Customer","firstName":"User1","lastName":"Name1","username":"user1","addresses":[{"$ref":"address","$id":ObjectID("579f21ae98684924944651c3")}],"cards":[{"$ref":"card","$id":ObjectID("579f21ae98684924944651c4")}]}
36+
];
37+
38+
39+
// Setup database connection before Dredd starts testing
40+
hooks.beforeAll((transactions, done) => {
41+
var MongoEndpoint = process.env.MONGO_ENDPOINT || 'mongodb://localhost:32769/data';
42+
MongoClient.connect(MongoEndpoint, function(err, conn) {
43+
if (err) {
44+
console.error(err);
45+
}
46+
db = conn;
47+
done(err);
48+
});
49+
});
50+
51+
hooks.beforeEach((transaction, done) => {
52+
db.dropDatabase(function (err, res) {
53+
var promisesToKeep = [
54+
db.collection('customer').insertMany(customer),
55+
db.collection('card').insertMany(card),
56+
db.collection('cart').insertMany(cart),
57+
db.collection('address').insertMany(address),
58+
db.collection('item').insertMany(item)
59+
];
60+
Promise.all(promisesToKeep).then(function(vls) {
61+
done();
62+
}, function(vls) {
63+
done();
64+
});
65+
})
66+
67+
});
68+
69+
70+
hooks.before("/carts/{customerId}/items > POST", function(transaction, done) {
71+
transaction.request.headers['Content-Type'] = 'application/json';
72+
transaction.request.body = JSON.stringify(
73+
{
74+
"itemId":"819e1fbf-8b7e-4f6d-811f-693534916a8b",
75+
"quantity": 20,
76+
"unitPrice" : 99.0
77+
}
78+
);
79+
80+
done();
81+
});
82+
83+
// TODO: Can't make POST and PUT work, skipping for now
84+
85+
// hooks.before("/carts/{customerId}/items > POST", function(transaction, done) {
86+
// transaction.skip = true;
87+
// done();
88+
// });
89+
90+
hooks.before("/carts/{customerId}/items > PATCH", function(transaction, done) {
91+
transaction.skip = true;
92+
done();
93+
});

cart_deploy_rsa.enc

3.17 KB
Binary file not shown.

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ else
2424
fi
2525
CODE_DIR=$(cd $SCRIPT_DIR/..; pwd)
2626
echo $CODE_DIR
27-
$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.2-jdk-8 mvn -DskipTests package
27+
$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.2-jdk-8 mvn -q -DskipTests package
2828

2929
cp $CODE_DIR/target/*.jar $CODE_DIR/docker/cart
3030

0 commit comments

Comments
 (0)