Skip to content

Commit

Permalink
feature: WEOS-1342
Browse files Browse the repository at this point in the history
- Fixed e2e step(theFieldShouldHaveTodaysDate) to be more dynamic
- Removed local copy in UpdateTime func
  • Loading branch information
RandyDeo committed Mar 15, 2022
1 parent 6eb36e3 commit 9176aa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
42 changes: 11 additions & 31 deletions end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
weosContext "github.com/wepala/weos/context"
"io"
"mime/multipart"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -74,11 +74,10 @@ var token string
var xfolderError error
var xfolderName string
var contextWithValues context.Context
var createdDate interface{}
var updatedDate interface{}
var mockProjections map[string]*ProjectionMock
var mockEventStores map[string]*EventRepositoryMock
var expectedContentType string
var contentEntity map[string]interface{}

type FilterProperties struct {
Operator string
Expand Down Expand Up @@ -483,7 +482,7 @@ func theIsCreated(contentType string, details *godog.Table) error {
}
}

contentEntity := map[string]interface{}{}
contentEntity = map[string]interface{}{}
var result *gorm.DB
//ETag would help with this
for key, value := range compare {
Expand All @@ -507,8 +506,6 @@ func theIsCreated(contentType string, details *godog.Table) error {
}
}

createdDate = contentEntity["created"]

contentTypeID[strings.ToLower(contentType)] = true
return nil
}
Expand Down Expand Up @@ -882,7 +879,7 @@ func theIsUpdated(contentType string, details *godog.Table) error {
}
}

contentEntity := map[string]interface{}{}
contentEntity = map[string]interface{}{}
var result *gorm.DB
//ETag would help with this
for key, value := range compare {
Expand Down Expand Up @@ -914,8 +911,6 @@ func theIsUpdated(contentType string, details *godog.Table) error {
}
}

updatedDate = contentEntity["updated"]

contentTypeID[strings.ToLower(contentType)] = true
return nil
}
Expand Down Expand Up @@ -1756,30 +1751,15 @@ func theFieldShouldHaveTodaysDate(field string) error {

switch dbconfig.Driver {
case "postgres", "mysql":
switch field {
case "created":
crDate := createdDate.(time.Time).Format("2006-01-02")
if !strings.Contains(crDate, todaysDate) {
return fmt.Errorf("expected the created date: %s to contain the current date: %s ", crDate, todaysDate)
}
case "updated":
upDate := updatedDate.(time.Time).Format("2006-01-02")
if !strings.Contains(upDate, todaysDate) {
return fmt.Errorf("expected the created date: %s to contain the current date: %s ", upDate, todaysDate)
}
date := contentEntity[field].(time.Time).Format("2006-01-02")
if !strings.Contains(date, todaysDate) {
return fmt.Errorf("expected the %s date: %s to contain the current date: %s ", field, date, todaysDate)
}

case "sqlite3":
switch field {
case "created":
crDate := createdDate.(string)
if !strings.Contains(crDate, todaysDate) {
return fmt.Errorf("expected the created date: %s to contain the current date: %s ", crDate, todaysDate)
}
case "updated":
upDate := updatedDate.(string)
if !strings.Contains(upDate, todaysDate) {
return fmt.Errorf("expected the created date: %s to contain the current date: %s ", upDate, todaysDate)
}
date := contentEntity[field].(string)
if !strings.Contains(date, todaysDate) {
return fmt.Errorf("expected the %s date: %s to contain the current date: %s ", field, date, todaysDate)
}
}

Expand Down
3 changes: 1 addition & 2 deletions model/content_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,9 @@ func (w *ContentEntity) UnmarshalJSON(data []byte) error {

//UpdateTime updates auto update time values on the payload
func (w *ContentEntity) UpdateTime(operationID string, data []byte) ([]byte, error) {
scheme := w.Schema
payload := map[string]interface{}{}
json.Unmarshal(data, &payload)
for key, p := range scheme.Properties {
for key, p := range w.Schema.Properties {
routes := []string{}
routeBytes, _ := json.Marshal(p.Value.Extensions["x-update"])
json.Unmarshal(routeBytes, &routes)
Expand Down

0 comments on commit 9176aa6

Please sign in to comment.