(t *testing.T)
| 339 | } |
| 340 | |
| 341 | func TestMarshalOnePayload_omitIDString(t *testing.T) { |
| 342 | type Foo struct { |
| 343 | ID string `jsonapi:"primary,foo"` |
| 344 | Title string `jsonapi:"attr,title"` |
| 345 | } |
| 346 | |
| 347 | foo := &Foo{Title: "Foo"} |
| 348 | out := bytes.NewBuffer(nil) |
| 349 | if err := MarshalPayload(out, foo); err != nil { |
| 350 | t.Fatal(err) |
| 351 | } |
| 352 | |
| 353 | var jsonData map[string]interface{} |
| 354 | if err := json.Unmarshal(out.Bytes(), &jsonData); err != nil { |
| 355 | t.Fatal(err) |
| 356 | } |
| 357 | payload := jsonData["data"].(map[string]interface{}) |
| 358 | |
| 359 | // Verify that empty ID of type string gets omitted. See: |
| 360 | // https://github.com/google/jsonapi/issues/83#issuecomment-285611425 |
| 361 | _, ok := payload["id"] |
| 362 | if ok { |
| 363 | t.Fatal("Was expecting the data.id member to be omitted") |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func TestMarshall_invalidIDType(t *testing.T) { |
| 368 | type badIDStruct struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…