-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
les-test reference implementation test.
- Loading branch information
Robert Reppel
committed
Apr 21, 2018
1 parent
9cb3bb8
commit 1035fe1
Showing
8 changed files
with
315 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
EmlVersion: 0.1-alpha | ||
Solution: TODO List | ||
Contexts: | ||
- Name: TODO List | ||
Streams: | ||
- Stream: User | ||
Commands: | ||
- Command: | ||
Name: Register | ||
Parameters: | ||
- Name: userId | ||
Type: string | ||
Rules: | ||
- IsRequired | ||
- Name: notificationEmail | ||
Type: string | ||
Rules: [] | ||
Preconditions: [] | ||
Postconditions: | ||
- UserRegistered | ||
Events: | ||
- Event: | ||
Name: UserRegistered | ||
Properties: | ||
- Name: userId | ||
Type: string | ||
- Name: notificationEmail | ||
Type: string | ||
- Stream: TodoItem | ||
Commands: | ||
- Command: | ||
Name: AddItem | ||
Parameters: | ||
- Name: userId | ||
Type: string | ||
Rules: | ||
- MustExistIn UserLookup | ||
- Name: description | ||
Type: string | ||
Rules: [] | ||
- Name: todoitemId | ||
Type: string | ||
Rules: | ||
- IsRequired | ||
Preconditions: [] | ||
Postconditions: | ||
- TodoItemAdded | ||
Events: | ||
- Event: | ||
Name: TodoItemAdded | ||
Properties: | ||
- Name: description | ||
Type: string | ||
- Name: todoitemId | ||
Type: string | ||
Readmodels: | ||
- Readmodel: | ||
Name: UserLookup | ||
Key: userId | ||
SubscribesTo: | ||
- UserRegistered | ||
- Readmodel: | ||
Name: TODOList | ||
Key: todoitemId | ||
SubscribesTo: | ||
- TodoItemAdded | ||
Errors: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
api | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
EmlVersion: 0.1-alpha | ||
Solution: TODO List | ||
Contexts: | ||
- Name: TODO List | ||
Streams: | ||
- Stream: User | ||
Commands: | ||
- Command: | ||
Name: Register | ||
Parameters: | ||
- Name: userId | ||
Type: string | ||
Rules: | ||
- IsRequired | ||
- Name: notificationEmail | ||
Type: string | ||
Rules: [] | ||
Preconditions: [] | ||
Postconditions: | ||
- UserRegistered | ||
Events: | ||
- Event: | ||
Name: UserRegistered | ||
Properties: | ||
- Name: userId | ||
Type: string | ||
- Name: notificationEmail | ||
Type: string | ||
- Stream: TodoItem | ||
Commands: | ||
- Command: | ||
Name: AddItem | ||
Parameters: | ||
- Name: userId | ||
Type: string | ||
Rules: | ||
- MustExistIn UserLookup | ||
- Name: description | ||
Type: string | ||
Rules: [] | ||
- Name: todoitemId | ||
Type: string | ||
Rules: | ||
- IsRequired | ||
Preconditions: [] | ||
Postconditions: | ||
- TodoItemAdded | ||
Events: | ||
- Event: | ||
Name: TodoItemAdded | ||
Properties: | ||
- Name: description | ||
Type: string | ||
- Name: todoitemId | ||
Type: string | ||
Readmodels: | ||
- Readmodel: | ||
Name: UserLookup | ||
Key: userId | ||
SubscribesTo: | ||
- UserRegistered | ||
- Readmodel: | ||
Name: TODOList | ||
Key: todoitemId | ||
SubscribesTo: | ||
- TodoItemAdded | ||
Errors: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# TODO List | ||
# A reference system which exercises all available features in EMD 0.10.1-alpha. | ||
|
||
Register-> // userId, notificationEmail | ||
User Registered // userId, notificationEmail | ||
UserLookup* // userId, notificationEmail | ||
|
||
Add Item-> // userId, description | ||
TodoItem Added // description | ||
TODO List* // todoitemId, description | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
SHELL := /bin/bash | ||
|
||
.PHONY: test | ||
test: | ||
go run main.go | ||
|
||
.PHONY: setup | ||
setup: build-les build-les-node build-api | ||
|
||
.PHONY: teardown | ||
teardown: | ||
pushd api \ | ||
&& docker-compose down \ | ||
&& popd \ | ||
&& rm -fr api | ||
|
||
.PHONY: build-les | ||
build-les: | ||
cd ../les \ | ||
&& go build | ||
|
||
.PHONY: build-les-node | ||
build-les-node: | ||
cd ../les-node \ | ||
&& go build | ||
|
||
.PHONY: build-api | ||
build-api: | ||
../les/les convert \ | ||
&& ../les-node/les-node -b \ | ||
&& cd api && npm install && docker-compose up -d \ | ||
&& docker-compose restart api # workaround for race condition (eventstore not yet available when API starts) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Event Markup Language Compliance Test | ||
|
||
Tests whether an API created from EML by a builder such as les-node complies with the EML specification. | ||
|
||
* Are all the command processor end points working? | ||
* Are the read models working? | ||
* Are all the business rules implemented? | ||
* Are the required validation errors returned when executing invalid commands? | ||
|
||
## Howto | ||
|
||
```make setup && sleep 1 && make test``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
Event Markup Language Compliance Test | ||
Tests whether an API created from EML by a builder such as les-node complies with the EML specification. | ||
* Are all the command processor end points working? | ||
* Are the read models working? | ||
* Are all the business rules implemented? | ||
* Are the required validation errors returned when executing invalid commands? | ||
*/ | ||
package main | ||
|
||
import ( | ||
"github.com/verdverm/frisby" | ||
) | ||
|
||
const apiURI = "http://localhost:3001/api/v1" | ||
const testUserID = "4481c18058aa494fb033b65665c38de2" | ||
|
||
func main() { | ||
addingTodoListItemForUnknownUserFails() | ||
// When | ||
registeringUser() | ||
// Then | ||
userLookupReadmodelContainsUser() | ||
|
||
// When | ||
addingTodoListItem() | ||
// Then | ||
todoListContainsNewItem() | ||
// omittingMandatoryCommandParameterFails() | ||
|
||
frisby.Global.PrintReport() | ||
} | ||
|
||
func addingTodoListItemForUnknownUserFails() { | ||
frisby.Create("Executing valid Command succeeds."). | ||
SetHeader("Content-Type", "application/json"). | ||
SetHeader("Accept", "application/json, text/plain, */*"). | ||
Post(apiURI+"/TodoItem/AddItem"). | ||
SetJson(todoItem{ | ||
UserID: testUserID, | ||
Description: "Carpe Diem", | ||
TodoitemID: "10000"}). | ||
Send(). | ||
ExpectStatus(400). | ||
ExpectJson("message.0.field", "userId"). | ||
ExpectJson("message.0.msg", "userId does not exist."). | ||
ExpectJsonLength("message", 1) | ||
} | ||
|
||
func registeringUser() { | ||
frisby.Create("Executing valid registeringUser Command succeeds."). | ||
SetHeader("Content-Type", "application/json"). | ||
SetHeader("Accept", "application/json, text/plain, */*"). | ||
Post(apiURI + "/User/Register"). | ||
SetJson(user{UserID: testUserID, NotificationEmail: "[email protected]"}). | ||
Send(). | ||
ExpectStatus(202) | ||
} | ||
|
||
func addingTodoListItem() { | ||
frisby.Create("Executing valid Command succeeds."). | ||
SetHeader("Content-Type", "application/json"). | ||
SetHeader("Accept", "application/json, text/plain, */*"). | ||
Post(apiURI + "/TodoItem/AddItem"). | ||
SetJson(todoItem{UserID: testUserID, Description: "Carpe Diem", TodoitemID: "10000"}). | ||
Send(). | ||
ExpectStatus(202) | ||
} | ||
|
||
func userLookupReadmodelContainsUser() { | ||
frisby.Create("GET UserLookup Read Model succeeds."). | ||
Get(apiURI+"/r/UserLookup"). | ||
Send(). | ||
ExpectStatus(200). | ||
ExpectJson("0.userId", testUserID). | ||
ExpectJson("0.notificationEmail", "[email protected]") | ||
} | ||
|
||
func todoListContainsNewItem() { | ||
frisby.Create("GET Read Model succeeds."). | ||
Get(apiURI+"/r/TODOList"). | ||
Send(). | ||
ExpectStatus(200). | ||
ExpectJson("0.todoitemId", "10000"). | ||
ExpectJson("0.description", "Carpe Diem") | ||
} | ||
|
||
func omittingMandatoryCommandParameterFails() { | ||
frisby.Create("Omitting mandatory field fails."). | ||
SetHeader("Content-Type", "application/json"). | ||
SetHeader("Accept", "application/json, text/plain, */*"). | ||
Post(apiURI+"/TodoItem/AddItem"). | ||
SetJson(todoItem{Description: "Carpe Diem", TodoitemID: ""}). | ||
Send(). | ||
ExpectStatus(400). | ||
ExpectJson("message.0.field", "todoitemId"). | ||
ExpectJson("message.0.msg", "todoitemId is a required field."). | ||
ExpectJsonLength("message", 1) | ||
} | ||
|
||
type user struct { | ||
UserID string `json:"userId"` | ||
NotificationEmail string `json:"notificationEmail"` | ||
} | ||
|
||
type todoItem struct { | ||
UserID string `json:"userId"` | ||
TodoitemID string `json:"todoitemId"` | ||
Description string `json:"description"` | ||
} |