@@ -1295,6 +1295,120 @@ func TestUpdateTaskState(t *testing.T) {
12951295 })
12961296}
12971297
1298+ func TestUpdateJobCollectionID (t * testing.T ) {
1299+ Convey ("Given a job service and store with an existing job" , t , func () {
1300+ oldTime := time .Date (2024 , time .January , 10 , 12 , 0 , 0 , 0 , time .UTC )
1301+ fakeJob := & domain.Job {
1302+ ID : "test-job-id" ,
1303+ JobNumber : testJobNumber ,
1304+ Config : & domain.JobConfig {
1305+ CollectionID : "old-collection-id" ,
1306+ },
1307+ LastUpdated : oldTime ,
1308+ }
1309+
1310+ mockMongo := & storeMocks.MongoDBMock {
1311+ GetJobFunc : func (ctx context.Context , jobNumber int ) (* domain.Job , error ) {
1312+ return fakeJob , nil
1313+ },
1314+ UpdateJobFunc : func (ctx context.Context , job * domain.Job ) error {
1315+ return nil
1316+ },
1317+ }
1318+
1319+ mockStore := store.Datastore {
1320+ Backend : mockMongo ,
1321+ }
1322+
1323+ mockClients := clients.ClientList {}
1324+ cfg := & config.Config {EnableEventLogging : false }
1325+ jobService := Setup (& mockStore , & mockClients , cfg )
1326+
1327+ ctx := context .Background ()
1328+ newCollectionID := "new-collection-id"
1329+
1330+ Convey ("When UpdateJobCollectionID is called" , func () {
1331+ err := jobService .UpdateJobCollectionID (ctx , fakeJob .JobNumber , newCollectionID )
1332+
1333+ Convey ("Then the store should be called to update the job" , func () {
1334+ So (len (mockMongo .UpdateJobCalls ()), ShouldEqual , 1 )
1335+ So (mockMongo .UpdateJobCalls ()[0 ].Job .Config .CollectionID , ShouldEqual , newCollectionID )
1336+ So (mockMongo .UpdateJobCalls ()[0 ].Job .LastUpdated .After (oldTime ), ShouldBeTrue )
1337+
1338+ Convey ("And no error should be returned" , func () {
1339+ So (err , ShouldBeNil )
1340+ })
1341+ })
1342+ })
1343+ })
1344+
1345+ Convey ("Given a job service and store that returns an error when getting a job" , t , func () {
1346+ mockMongo := & storeMocks.MongoDBMock {
1347+ GetJobFunc : func (ctx context.Context , jobNumber int ) (* domain.Job , error ) {
1348+ return nil , appErrors .ErrJobNotFound
1349+ },
1350+ }
1351+
1352+ mockStore := store.Datastore {
1353+ Backend : mockMongo ,
1354+ }
1355+
1356+ mockClients := clients.ClientList {}
1357+ cfg := & config.Config {EnableEventLogging : false }
1358+ jobService := Setup (& mockStore , & mockClients , cfg )
1359+
1360+ ctx := context .Background ()
1361+
1362+ Convey ("When UpdateJobCollectionID is called" , func () {
1363+ err := jobService .UpdateJobCollectionID (ctx , testJobNumber , "new-collection-id" )
1364+
1365+ Convey ("Then the error should be returned and no update performed" , func () {
1366+ So (err , ShouldEqual , appErrors .ErrJobNotFound )
1367+ So (len (mockMongo .UpdateJobCalls ()), ShouldEqual , 0 )
1368+ })
1369+ })
1370+ })
1371+
1372+ Convey ("Given a job service and store that returns an error when updating a job" , t , func () {
1373+ fakeJob := & domain.Job {
1374+ ID : "test-job-id" ,
1375+ JobNumber : testJobNumber ,
1376+ Config : & domain.JobConfig {
1377+ CollectionID : "old-collection-id" ,
1378+ },
1379+ }
1380+
1381+ mockMongo := & storeMocks.MongoDBMock {
1382+ GetJobFunc : func (ctx context.Context , jobNumber int ) (* domain.Job , error ) {
1383+ return fakeJob , nil
1384+ },
1385+ UpdateJobFunc : func (ctx context.Context , job * domain.Job ) error {
1386+ return fmt .Errorf ("fake error for testing" )
1387+ },
1388+ }
1389+
1390+ mockStore := store.Datastore {
1391+ Backend : mockMongo ,
1392+ }
1393+
1394+ mockClients := clients.ClientList {}
1395+ cfg := & config.Config {EnableEventLogging : false }
1396+ jobService := Setup (& mockStore , & mockClients , cfg )
1397+
1398+ ctx := context .Background ()
1399+
1400+ Convey ("When UpdateJobCollectionID is called" , func () {
1401+ err := jobService .UpdateJobCollectionID (ctx , testJobNumber , "new-collection-id" )
1402+
1403+ Convey ("Then an error should be returned" , func () {
1404+ So (len (mockMongo .UpdateJobCalls ()), ShouldEqual , 1 )
1405+ So (err , ShouldNotBeNil )
1406+ So (err .Error (), ShouldContainSubstring , "failed to update job collection ID" )
1407+ })
1408+ })
1409+ })
1410+ }
1411+
12981412func TestGetJobTasks (t * testing.T ) {
12991413 Convey ("Given a job service and store that has stored tasks for a job" , t , func () {
13001414 mockMongo := & storeMocks.MongoDBMock {
0 commit comments