(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func TestCreateDraft(t *testing.T) { |
| 117 | mainHelper.Parallel(t) |
| 118 | th := Setup(t).InitBasic(t) |
| 119 | |
| 120 | th.Server.platform.SetConfigReadOnlyFF(false) |
| 121 | defer th.Server.platform.SetConfigReadOnlyFF(true) |
| 122 | |
| 123 | th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = true }) |
| 124 | |
| 125 | user := th.BasicUser |
| 126 | channel := th.BasicChannel |
| 127 | channel2 := th.CreateChannel(t, th.BasicTeam) |
| 128 | th.AddUserToChannel(t, user, channel2) |
| 129 | |
| 130 | draft1 := &model.Draft{ |
| 131 | CreateAt: 00001, |
| 132 | UpdateAt: 00001, |
| 133 | UserId: user.Id, |
| 134 | ChannelId: channel.Id, |
| 135 | Message: "draft", |
| 136 | } |
| 137 | |
| 138 | draft2 := &model.Draft{ |
| 139 | CreateAt: 00001, |
| 140 | UpdateAt: 00001, |
| 141 | UserId: user.Id, |
| 142 | ChannelId: channel2.Id, |
| 143 | Message: "draft2", |
| 144 | } |
| 145 | |
| 146 | t.Run("create draft", func(t *testing.T) { |
| 147 | draftResp, err := th.App.UpsertDraft(th.Context, draft1, "") |
| 148 | assert.Nil(t, err) |
| 149 | |
| 150 | assert.Equal(t, draft1.Message, draftResp.Message) |
| 151 | assert.Equal(t, draft1.ChannelId, draftResp.ChannelId) |
| 152 | }) |
| 153 | |
| 154 | t.Run("create draft with files", func(t *testing.T) { |
| 155 | // upload file |
| 156 | sent, readFileErr := testutils.ReadTestFile("test.png") |
| 157 | require.NoError(t, readFileErr) |
| 158 | |
| 159 | fileResp, uploadFileErr := th.App.UploadFile(th.Context, sent, channel.Id, "test.png") |
| 160 | assert.Nil(t, uploadFileErr) |
| 161 | |
| 162 | draftWithFiles := draft2 |
| 163 | draftWithFiles.FileIds = []string{fileResp.Id} |
| 164 | |
| 165 | draftResp, err := th.App.UpsertDraft(th.Context, draftWithFiles, "") |
| 166 | assert.Nil(t, err) |
| 167 | |
| 168 | assert.Equal(t, draftWithFiles.Message, draftResp.Message) |
| 169 | assert.Equal(t, draftWithFiles.ChannelId, draftResp.ChannelId) |
| 170 | assert.ElementsMatch(t, draftWithFiles.FileIds, draftResp.FileIds) |
| 171 | }) |
| 172 | } |
| 173 |
nothing calls this directly
no test coverage detected
searching dependent graphs…