Skip to content

Commit

Permalink
🐛 (model/question) fix parsing, add export->import test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shion1305 committed May 26, 2024
1 parent 84629be commit 2dbe3f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions svc/pkg/domain/model/question/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ func (q FileQuestion) Export() (*StandardQuestion, error) {

qt := []bool{q.FileTypes.AcceptAny, q.FileTypes.AcceptImage, q.FileTypes.AcceptPDF}
customs[FileQuestionFileTypeField] = qt
customs[FileImageConstraintField] = q.ImageFileConstraint.Export()
return NewStandardQuestion(TypeFile, q.ID, q.FormID, q.Text, customs), nil
}
2 changes: 2 additions & 0 deletions svc/pkg/domain/model/question/file_constraint_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,7 @@ func (c ImageFileConstraint) Export() map[string]interface{} {
result[FileImageConstraintWidth] = widthC
heightC := c.Height.Export()
result[FileImageConstraintHeight] = heightC
ratioC := c.Ratio.Export()
result[FileImageConstraintRatio] = ratioC
return result
}
9 changes: 9 additions & 0 deletions svc/pkg/domain/model/question/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func TestImportFileQuestion(t *testing.T) {
Type: TypeFile,
Customs: map[string]interface{}{
FileQuestionFileTypeField: []bool{false, true, false},
FileImageConstraintField: map[string]interface{}{
FileImageConstraintRatio: map[string]interface{}{},
FileImageConstraintWidth: map[string]interface{}{},
FileImageConstraintHeight: map[string]interface{}{},
},
},
},
want: NewFileQuestion(SampleID1,
Expand Down Expand Up @@ -121,6 +126,10 @@ func TestImportFileQuestion(t *testing.T) {
assert.Equal(t, tc.want.Width, got.Width)
assert.Equal(t, tc.want.Height, got.Height)
assert.Equal(t, tc.want.Ratio, got.Ratio)
export, err := got.Export()
if assert.NoError(t, err) {
assert.Equal(t, tc.from, *export)
}
})
}
}

0 comments on commit 2dbe3f6

Please sign in to comment.