github.com/companieshouse/insolvency-api@v0.0.0-20231024103413-440c973d9e9b/dao/mongo_test.go (about) 1 package dao 2 3 import ( 4 "testing" 5 6 "github.com/companieshouse/insolvency-api/config" 7 "github.com/companieshouse/insolvency-api/models" 8 gomock "github.com/golang/mock/gomock" 9 10 "go.mongodb.org/mongo-driver/mongo" 11 12 . "github.com/smartystreets/goconvey/convey" 13 ) 14 15 func NewGetMongoDatabase(mongoDBURL, databaseName string) MongoDatabaseInterface { 16 return getMongoClient(mongoDBURL).Database(databaseName) 17 } 18 19 func setUp(t *testing.T) MongoService { 20 mockCtrl := gomock.NewController(t) 21 defer mockCtrl.Finish() 22 23 client = &mongo.Client{} 24 cfg, _ := config.Get() 25 dataBase := NewGetMongoDatabase("mongoDBURL", "databaseName") 26 27 mongoService := MongoService{ 28 db: dataBase, 29 CollectionName: cfg.MongoCollection, 30 } 31 return mongoService 32 } 33 34 func TestUnitCreateInsolvencyResource(t *testing.T) { 35 36 Convey("Create Insolvency Resource", t, func() { 37 38 expectedInsolvency := models.InsolvencyResourceDao{} 39 40 mongoService := setUp(t) 41 42 err, _ := mongoService.CreateInsolvencyResource(&expectedInsolvency) 43 44 So(err.Error(), ShouldEqual, "there was a problem creating an insolvency case for this transaction id: the Find operation must have a Deployment set before Execute can be called") 45 }) 46 } 47 48 func TestUnitGetInsolvencyResource(t *testing.T) { 49 50 Convey("Get Insolvency Resource", t, func() { 51 52 mongoService := setUp(t) 53 54 _, err := mongoService.GetInsolvencyResource("transactionID") 55 56 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction [transactionID]") 57 }) 58 } 59 60 func TestUnitCreatePractitionersResource(t *testing.T) { 61 62 Convey("Create practitioners resource", t, func() { 63 64 mongoService := setUp(t) 65 66 practitionerResource := models.PractitionerResourceDao{} 67 68 err, _ := mongoService.CreatePractitionersResource(&practitionerResource, "transactionID") 69 70 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 71 }) 72 } 73 74 func TestUnitGetPractitionerResources(t *testing.T) { 75 76 Convey("Get practitioner resources", t, func() { 77 78 mongoService := setUp(t) 79 80 _, err := mongoService.GetPractitionerResources("transactionID") 81 82 So(err.Error(), ShouldEqual, "the Find operation must have a Deployment set before Execute can be called") 83 }) 84 } 85 86 func TestUnitGetPractitionerResource(t *testing.T) { 87 88 Convey("Get practitioner resources", t, func() { 89 90 mongoService := setUp(t) 91 92 _, err := mongoService.GetPractitionerResource("practitionerID", "transactionID") 93 94 So(err.Error(), ShouldEqual, "the Find operation must have a Deployment set before Execute can be called") 95 }) 96 } 97 98 func TestUnitDeletePractitioner(t *testing.T) { 99 100 Convey("Delete practitioner", t, func() { 101 102 mongoService := setUp(t) 103 104 err, _ := mongoService.DeletePractitioner("practitionerID", "transactionID") 105 106 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 107 }) 108 } 109 110 func TestUnitAppointPractitioner(t *testing.T) { 111 112 Convey("Appoint practitioner", t, func() { 113 114 mongoService := setUp(t) 115 116 appointmentResource := models.AppointmentResourceDao{} 117 118 err, _ := mongoService.AppointPractitioner(&appointmentResource, "transactionID", "practitionerID") 119 120 So(err.Error(), ShouldEqual, "could not update practitioner appointment for practitionerID practitionerID: the Update operation must have a Deployment set before Execute can be called") 121 }) 122 } 123 124 func TestUnitDeletePractitionerAppointment(t *testing.T) { 125 126 Convey("Delete practitioner appointment", t, func() { 127 128 mongoService := setUp(t) 129 130 err, _ := mongoService.DeletePractitionerAppointment("transactionID", "practitionerID") 131 132 So(err.Error(), ShouldEqual, "could not update practitioner appointment for practitionerID practitionerID: the Update operation must have a Deployment set before Execute can be called") 133 }) 134 } 135 136 func TestUnitAddAttachmentToInsolvencyResource(t *testing.T) { 137 138 Convey("Add attachment to insolvency resource", t, func() { 139 140 mongoService := setUp(t) 141 142 _, err := mongoService.AddAttachmentToInsolvencyResource("transactionID", "fileID", "attachmentType") 143 144 So(err.Error(), ShouldEqual, "error updating mongo for transaction [transactionID]: [the Update operation must have a Deployment set before Execute can be called]") 145 }) 146 } 147 148 func TestUnitGetAttachmentResources(t *testing.T) { 149 150 Convey("Get attachment resources", t, func() { 151 152 mongoService := setUp(t) 153 154 _, err := mongoService.GetAttachmentResources("transactionID") 155 156 So(err.Error(), ShouldEqual, "the Find operation must have a Deployment set before Execute can be called") 157 }) 158 } 159 160 func TestUnitGetAttachmentFromInsolvencyResource(t *testing.T) { 161 162 Convey("Get attachment from insolvency resource", t, func() { 163 164 mongoService := setUp(t) 165 166 _, err := mongoService.GetAttachmentFromInsolvencyResource("transactionID", "fileID") 167 168 So(err.Error(), ShouldEqual, "the Find operation must have a Deployment set before Execute can be called") 169 }) 170 } 171 172 func TestUnitDeleteAttachmentResource(t *testing.T) { 173 174 Convey("Delete attachment status", t, func() { 175 176 mongoService := setUp(t) 177 178 _, err := mongoService.DeleteAttachmentResource("transactionID", "attachmentID") 179 180 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 181 }) 182 } 183 184 func TestUnitUpdateAttachmentStatus(t *testing.T) { 185 186 Convey("Update attachment status", t, func() { 187 188 mongoService := setUp(t) 189 190 _, err := mongoService.UpdateAttachmentStatus("transactionID", "attachmentID", "avStatus") 191 192 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 193 }) 194 } 195 196 func TestUnitCreateResolutionResource(t *testing.T) { 197 198 Convey("Create resolution resource", t, func() { 199 200 mongoService := setUp(t) 201 202 resolutionResource := models.ResolutionResourceDao{} 203 204 _, err := mongoService.CreateResolutionResource(&resolutionResource, "transactionID") 205 206 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 207 }) 208 } 209 210 func TestUnitCreateStatementOfAffairsResource(t *testing.T) { 211 212 Convey("Create statement of affairs resource", t, func() { 213 214 mongoService := setUp(t) 215 216 statementResource := models.StatementOfAffairsResourceDao{} 217 218 _, err := mongoService.CreateStatementOfAffairsResource(&statementResource, "transactionID") 219 220 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 221 }) 222 } 223 224 func TestUnitGetStatementOfAffairsResource(t *testing.T) { 225 226 Convey("Get statement of affairs resource", t, func() { 227 228 mongoService := setUp(t) 229 230 _, err := mongoService.GetStatementOfAffairsResource("transactionID") 231 232 So(err.Error(), ShouldEqual, "the Find operation must have a Deployment set before Execute can be called") 233 }) 234 } 235 236 func TestUnitDeleteStatementOfAffairsResource(t *testing.T) { 237 238 Convey("Delete statement of affairs resource", t, func() { 239 240 mongoService := setUp(t) 241 242 _, err := mongoService.DeleteStatementOfAffairsResource("transactionID") 243 244 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 245 }) 246 } 247 248 func TestUnitCreateProgressReportResource(t *testing.T) { 249 250 Convey("Create progress report resource", t, func() { 251 252 mongoService := setUp(t) 253 254 progressReport := models.ProgressReportResourceDao{} 255 256 _, err := mongoService.CreateProgressReportResource(&progressReport, "transactionID") 257 258 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 259 }) 260 } 261 262 func TestUnitGetProgressReportResource(t *testing.T) { 263 264 Convey("Get progress report resource", t, func() { 265 266 mongoService := setUp(t) 267 268 _, err := mongoService.GetProgressReportResource("transactionID") 269 270 So(err.Error(), ShouldEqual, "the Find operation must have a Deployment set before Execute can be called") 271 }) 272 } 273 274 func TestUnitDeleteProgressReportResource(t *testing.T) { 275 276 Convey("Delete progress report", t, func() { 277 278 MongoService := setUp(t) 279 280 _, err := MongoService.DeleteProgressReportResource("transactionID") 281 282 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 283 284 }) 285 } 286 287 func TestUnitGetResolutionResource(t *testing.T) { 288 289 Convey("Get resolution resource", t, func() { 290 291 mongoService := setUp(t) 292 293 _, err := mongoService.GetResolutionResource("transactionID") 294 295 So(err.Error(), ShouldEqual, "the Find operation must have a Deployment set before Execute can be called") 296 }) 297 } 298 299 func TestUnitDeleteResolutionResource(t *testing.T) { 300 Convey("Delete resolution resource", t, func() { 301 302 mongoService := setUp(t) 303 304 _, err := mongoService.DeleteResolutionResource("transactionID") 305 306 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 307 }) 308 } 309 310 func TestUnitDeleteResource(t *testing.T) { 311 Convey("DeleteResource", t, func() { 312 313 MongoService := setUp(t) 314 315 _, err := MongoService.DeleteResource("transactionID", "progress-report") 316 317 So(err.Error(), ShouldEqual, "there was a problem handling your request for transaction id transactionID") 318 }) 319 }