Skip to content

Commit

Permalink
Merge pull request #252 from wepala/feature/251
Browse files Browse the repository at this point in the history
feature/251
  • Loading branch information
akeemphilbert authored Mar 8, 2023
2 parents 136116b + 752895e commit 119e0af
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions controllers/rest/fixtures/blog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ components:
- "null"
- unpublished
- published
date:
type: string
nullable: true
format: date-time
image:
type: string
format: byte
Expand Down
6 changes: 3 additions & 3 deletions model/content_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (w *ContentEntity) IsEnumValid(propertyName string, property *openapi3.Sche
} else if property.Value.Format == "date-time" {
for _, v := range property.Value.Enum {
if val, ok := v.(string); ok {
currTime, _ := time.Parse("2006-01-02T15:04:05Z", val)
currTime, _ := time.Parse(time.RFC3339, val)
currentTime := NewTime(currTime)
enumFound = enumFound || value.(*Time).String() == currentTime.String()
}
Expand Down Expand Up @@ -295,9 +295,9 @@ func (w *ContentEntity) SetValue(schema *openapi3.Schema, data map[string]interf
case "date-time":
//if the value is a string let's try to convert to time
if value, ok := data[k].(string); ok {
ttime, err := time.Parse("2006-01-02T15:04:05Z", value)
ttime, err := time.Parse(time.RFC3339, value)
if err != nil {
return nil, NewDomainError(fmt.Sprintf("invalid date time set for '%s' it should be in the format '2006-01-02T15:04:05Z', got '%s'", k, value), w.Schema.Title, w.ID, err)
return nil, NewDomainError(fmt.Sprintf("invalid date time set for '%s' it should be in the format '%s', got '%s'", k, time.RFC3339, value), w.Schema.Title, w.ID, err)
}
data[k] = NewTime(ttime)
}
Expand Down
21 changes: 21 additions & 0 deletions model/content_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ func TestContentEntity_IsValid(t *testing.T) {
}
}
})

t.Run("Testing date-time", func(t *testing.T) {
mockBlog := map[string]interface{}{"title": "test 1", "description": "New Description", "url": "www.NewBlog.com", "date": "2022-01-02T15:04:05Z"}
payload, err := json.Marshal(mockBlog)
if err != nil {
t.Fatalf("error converting payload to bytes %s", err)
}

entity, err := new(model.ContentEntity).FromSchemaWithValues(ctx, swagger.Components.Schemas["Blog"].Value, payload)
if err != nil {
t.Fatalf("unexpected error instantiating content entity '%s'", err)
}

if entity.GetString("title") != "test 1" {
t.Errorf("expected the title to be '%s', got '%s'", "test 1", entity.GetString("Title"))
}
isValid := entity.IsValid()
if !isValid {
t.Fatalf("unexpected error expected entity to be valid got invalid '%s'", entity.GetErrors()[0])
}
})
}

func TestContentEntity_Update(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions model/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 119e0af

Please sign in to comment.