@@ -13,6 +13,7 @@ import (
13
13
"time"
14
14
15
15
"github.com/ory/dockertest/v3"
16
+ "github.com/samber/lo"
16
17
17
18
"github.com/rudderlabs/rudder-go-kit/stats"
18
19
@@ -130,12 +131,15 @@ func TestManager_InsertJobHandler(t *testing.T) {
130
131
uploadsRepo := repo .NewUploads (db , repo .WithNow (func () time.Time {
131
132
return now
132
133
}))
133
- tableUploadsRepo := repo .NewTableUploads (db , config .New (), repo .WithNow (func () time.Time {
134
+ tuRepo := repo .NewTableUploads (db , config .New (), repo .WithNow (func () time.Time {
134
135
return now
135
136
}))
136
137
stagingRepo := repo .NewStagingFiles (db , config .New (), repo .WithNow (func () time.Time {
137
138
return now
138
139
}))
140
+ srcRepo := repo .NewSource (db , repo .WithNow (func () time.Time {
141
+ return now
142
+ }))
139
143
140
144
stagingFile := model.StagingFile {
141
145
WorkspaceID : workspaceID ,
@@ -175,7 +179,7 @@ func TestManager_InsertJobHandler(t *testing.T) {
175
179
}})
176
180
require .NoError (t , err )
177
181
178
- err = tableUploadsRepo .Insert (ctx , uploadID , []string {
182
+ err = tuRepo .Insert (ctx , uploadID , []string {
179
183
"test_table_1" ,
180
184
"test_table_2" ,
181
185
"test_table_3" ,
@@ -212,6 +216,26 @@ func TestManager_InsertJobHandler(t *testing.T) {
212
216
require .NoError (t , err )
213
217
require .Equal (t , "invalid payload: source_id is required\n " , string (b ))
214
218
})
219
+ t .Run ("empty tables" , func (t * testing.T ) {
220
+ req := httptest .NewRequest (http .MethodPost , "/v1/warehouse/jobs" , bytes .NewReader ([]byte (`
221
+ {
222
+ "source_id": "test_invalid_source_id",
223
+ "destination_id": "test_invalid_destination_id",
224
+ "job_run_id": "test_invalid_job_run_id",
225
+ "task_run_id": "test_invalid_task_run_id",
226
+ "async_job_type": "deletebyjobrunid"
227
+ }
228
+ ` )))
229
+ resp := httptest .NewRecorder ()
230
+
231
+ sourceManager := New (config .New (), logger .NOP , stats .NOP , db , & mockPublisher {})
232
+ sourceManager .InsertJobHandler (resp , req )
233
+ require .Equal (t , http .StatusInternalServerError , resp .Code )
234
+
235
+ b , err := io .ReadAll (resp .Body )
236
+ require .NoError (t , err )
237
+ require .Equal (t , "can't insert source jobs\n " , string (b ))
238
+ })
215
239
t .Run ("success" , func (t * testing.T ) {
216
240
req := httptest .NewRequest (http .MethodPost , "/v1/warehouse/jobs" , bytes .NewReader ([]byte (`
217
241
{
@@ -233,9 +257,12 @@ func TestManager_InsertJobHandler(t *testing.T) {
233
257
require .NoError (t , err )
234
258
require .Nil (t , insertResponse .Err )
235
259
require .Len (t , insertResponse .JobIds , 5 )
236
- })
237
- t .Run ("exclude tables" , func (t * testing.T ) {
238
- // discards, merge rules and mapping tables should be excluded
260
+
261
+ sourceJobs , err := srcRepo .GetToProcess (ctx , 100 )
262
+ require .NoError (t , err )
263
+ require .ElementsMatch (t , []string {"test_table_1" , "test_table_2" , "test_table_3" , "test_table_4" , "test_table_5" }, lo .Map (sourceJobs , func (item model.SourceJob , _ int ) string {
264
+ return item .TableName
265
+ }))
239
266
})
240
267
}
241
268
0 commit comments