Skip to content

Commit

Permalink
Make tests more reliable, improve content-type support
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed Mar 30, 2020
1 parent 29f8ae8 commit 332ed37
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/app/api/internal/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (o *Output) OK(w http.ResponseWriter, message string) (int, error) {
r.Body.Message = message

// Write the content.
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(r.Body)

return http.StatusOK, nil
Expand All @@ -50,8 +50,8 @@ func (o *Output) Created(w http.ResponseWriter, recordID string) (int, error) {
r.Body.RecordID = recordID

// Write the content.
w.WriteHeader(http.StatusCreated)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
_ = json.NewEncoder(w).Encode(r.Body)

return http.StatusCreated, nil
Expand Down
9 changes: 6 additions & 3 deletions src/app/api/pkg/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"reflect"
"strings"

validator "gopkg.in/go-playground/validator.v9"
)
Expand Down Expand Up @@ -56,8 +57,10 @@ func (b *Binder) Unmarshal(iface interface{}, r *http.Request) (err error) {
m := make(map[string]interface{})

// Try to auto detect data type based on on the header.
switch r.Header.Get("Content-Type") {
case "", "application/x-www-form-urlencoded":
// Header can having multiple values separated by a semicolon.
ct := r.Header.Get("Content-Type")
switch true {
case ct == "", strings.Contains(ct, "application/x-www-form-urlencoded"):
// Parse the form.
err = r.ParseForm()
if err != nil {
Expand All @@ -67,7 +70,7 @@ func (b *Binder) Unmarshal(iface interface{}, r *http.Request) (err error) {
for k, vv := range r.Form {
m[k] = vv[0]
}
case "application/json":
case strings.Contains(ct, "application/json"):
// Decode to the interface.
err = json.NewDecoder(r.Body).Decode(&m)
r.Body.Close()
Expand Down
1 change: 1 addition & 0 deletions src/app/api/store/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (x *NoteStore) FindAllByUser(dest *NoteGroup, userID string) (total int, er
SELECT *
FROM note
WHERE user_id = ?
ORDER BY message ASC
`,
userID)
return len(*dest), x.db.SuppressNoRowsError(err)
Expand Down
8 changes: 4 additions & 4 deletions src/app/ui/test/e2e/integration/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ describe('test the basic functionality', function() {
.should('have.length', 2)

cy.get('#listTodo>li')
.eq(0)
.eq(1)
.find('input')
.should('have.value', 'hello world')
.should('have.value', 'hello universe')

cy.get('#listTodo>li')
.eq(1)
.eq(0)
.find('input')
.should('have.value', 'hello universe')
.should('have.value', 'hello world')
})

it('edit the 2nd note', function() {
Expand Down

0 comments on commit 332ed37

Please sign in to comment.