()
| 448 | } |
| 449 | |
| 450 | func (s *MessageSuite) Test_CreateMessage_WithExtras() { |
| 451 | auth.RegisterAuthentication(s.ctx, nil, 4, "app-token") |
| 452 | s.db.User(4).AppWithTokenAndName(8, "app-token", "Application name") |
| 453 | |
| 454 | t, _ := time.Parse("2006/01/02", "2017/01/02") |
| 455 | timeNow = func() time.Time { return t } |
| 456 | defer func() { timeNow = time.Now }() |
| 457 | |
| 458 | s.ctx.Request = httptest.NewRequest("POST", "/message", strings.NewReader(`{"message": "mymessage", "title": "msg with extras", "extras": {"gotify::test":{"int":1,"float":0.5,"string":"test","array":[1,2,3]}}}`)) |
| 459 | s.ctx.Request.Header.Set("Content-Type", "application/json") |
| 460 | |
| 461 | s.a.CreateMessage(s.ctx) |
| 462 | |
| 463 | msgs, err := s.db.GetMessagesByApplication(8) |
| 464 | assert.NoError(s.T(), err) |
| 465 | expected := &model.MessageExternal{ |
| 466 | ID: 1, |
| 467 | ApplicationID: 8, |
| 468 | Message: "mymessage", |
| 469 | Title: "msg with extras", |
| 470 | Date: t, |
| 471 | Priority: intPtr(0), |
| 472 | Extras: map[string]interface{}{ |
| 473 | "gotify::test": map[string]interface{}{ |
| 474 | "string": "test", |
| 475 | "array": []interface{}{float64(1), float64(2), float64(3)}, |
| 476 | "int": float64(1), |
| 477 | "float": float64(0.5), |
| 478 | }, |
| 479 | }, |
| 480 | } |
| 481 | assert.Len(s.T(), msgs, 1) |
| 482 | |
| 483 | assert.Equal(s.T(), expected, toExternalMessage(msgs[0])) |
| 484 | |
| 485 | assert.Equal(s.T(), 200, s.recorder.Code) |
| 486 | assert.Equal(s.T(), uint(1), s.notifiedMessage.ID) |
| 487 | } |
| 488 | |
| 489 | func (s *MessageSuite) Test_CreateMessage_failWhenPriorityNotNumber() { |
| 490 | auth.RegisterAuthentication(s.ctx, nil, 4, "app-token") |
nothing calls this directly
no test coverage detected