Skip to content

Commit

Permalink
Merge #6
Browse files Browse the repository at this point in the history
6: Insert: Auto-generate UserID if absent r=Jaskaranbir a=bhupeshbhatia



Co-authored-by: bhupeshbhatia <bhatiabh@sheridancollege.ca>
  • Loading branch information
ninja-bruh and bhupeshbhatia committed Nov 1, 2018
2 parents 6fca6c0 + 8fb5b81 commit b0a6a02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
21 changes: 12 additions & 9 deletions user/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ func Insert(collection *mongo.Collection, event *model.Event) *model.KafkaRespon
}

if user.UserID == (uuuid.UUID{}) {
err = errors.New("missing UserID")
err = errors.Wrap(err, "Insert")
log.Println(err)
return &model.KafkaResponse{
AggregateID: event.AggregateID,
CorrelationID: event.CorrelationID,
Error: err.Error(),
ErrorCode: InternalError,
UUID: event.TimeUUID,
userID, err := uuuid.NewV4()
if err != nil {
err = errors.Wrap(err, "Insert: Error generating UserID")
log.Println(err)
return &model.KafkaResponse{
AggregateID: event.AggregateID,
CorrelationID: event.CorrelationID,
Error: err.Error(),
ErrorCode: InternalError,
UUID: event.TimeUUID,
}
}
user.UserID = userID
}
if user.FirstName == "" {
err = errors.New("missing FirstName")
Expand Down
31 changes: 0 additions & 31 deletions user/user_validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,6 @@ var _ = Describe("UserAggregate", func() {
}
})

It("should return error if userID is empty", func() {
user.UserID = uuuid.UUID{}
marshalUser, err := json.Marshal(user)
Expect(err).ToNot(HaveOccurred())

timeUUID, err := uuuid.NewV1()
Expect(err).ToNot(HaveOccurred())
cid, err := uuuid.NewV4()
Expect(err).ToNot(HaveOccurred())
uid, err := uuuid.NewV4()
Expect(err).ToNot(HaveOccurred())

mockEvent := &model.Event{
Action: "insert",
CorrelationID: cid,
AggregateID: 1,
Data: marshalUser,
Timestamp: time.Now(),
UserUUID: uid,
TimeUUID: timeUUID,
Version: 3,
YearBucket: 2018,
}
kr := Insert(nil, mockEvent)
Expect(kr.AggregateID).To(Equal(mockEvent.AggregateID))
Expect(kr.CorrelationID).To(Equal(mockEvent.CorrelationID))
Expect(kr.Error).ToNot(BeEmpty())
Expect(kr.ErrorCode).To(Equal(int16(InternalError)))
Expect(kr.UUID).To(Equal(mockEvent.TimeUUID))
})

It("should return error if firstName is empty", func() {
user.FirstName = ""
marshalUser, err := json.Marshal(user)
Expand Down

0 comments on commit b0a6a02

Please sign in to comment.