github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/app/job_test.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 9 "github.com/mattermost/mattermost-server/model" 10 "github.com/mattermost/mattermost-server/store" 11 ) 12 13 func TestGetJob(t *testing.T) { 14 th := Setup() 15 defer th.TearDown() 16 17 status := &model.Job{ 18 Id: model.NewId(), 19 Status: model.NewId(), 20 } 21 if result := <-th.App.Srv.Store.Job().Save(status); result.Err != nil { 22 t.Fatal(result.Err) 23 } 24 25 defer th.App.Srv.Store.Job().Delete(status.Id) 26 27 if received, err := th.App.GetJob(status.Id); err != nil { 28 t.Fatal(err) 29 } else if received.Id != status.Id || received.Status != status.Status { 30 t.Fatal("inccorrect job status received") 31 } 32 } 33 34 func TestGetJobByType(t *testing.T) { 35 th := Setup() 36 defer th.TearDown() 37 38 jobType := model.NewId() 39 40 statuses := []*model.Job{ 41 { 42 Id: model.NewId(), 43 Type: jobType, 44 CreateAt: 1000, 45 }, 46 { 47 Id: model.NewId(), 48 Type: jobType, 49 CreateAt: 999, 50 }, 51 { 52 Id: model.NewId(), 53 Type: jobType, 54 CreateAt: 1001, 55 }, 56 } 57 58 for _, status := range statuses { 59 store.Must(th.App.Srv.Store.Job().Save(status)) 60 defer th.App.Srv.Store.Job().Delete(status.Id) 61 } 62 63 if received, err := th.App.GetJobsByType(jobType, 0, 2); err != nil { 64 t.Fatal(err) 65 } else if len(received) != 2 { 66 t.Fatal("received wrong number of statuses") 67 } else if received[0].Id != statuses[2].Id { 68 t.Fatal("should've received newest job first") 69 } else if received[1].Id != statuses[0].Id { 70 t.Fatal("should've received second newest job second") 71 } 72 73 if received, err := th.App.GetJobsByType(jobType, 2, 2); err != nil { 74 t.Fatal(err) 75 } else if len(received) != 1 { 76 t.Fatal("received wrong number of statuses") 77 } else if received[0].Id != statuses[1].Id { 78 t.Fatal("should've received oldest job last") 79 } 80 }