Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using eFormCore;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microting.eFormApi.BasePn.Abstractions;
using Microting.TimePlanningBase.Infrastructure.Data.Entities;
using NSubstitute;
Expand All @@ -24,6 +25,7 @@ public class PictureSnapshotServiceTests : TestBaseSetup
private IUserService _userService;
private ITimePlanningLocalizationService _localizationService;
private IEFormCoreService _coreService;
private Microsoft.Extensions.Logging.ILogger<TimePlanningPictureSnapshotService> _logger;

[SetUp]
public async Task SetUp()
Expand All @@ -36,9 +38,10 @@ public async Task SetUp()
_localizationService.GetString(Arg.Any<string>()).Returns(x => x[0]?.ToString());

_coreService = Substitute.For<IEFormCoreService>();
_logger = Substitute.For<Microsoft.Extensions.Logging.ILogger<TimePlanningPictureSnapshotService>>();

_pictureSnapshotService = new TimePlanningPictureSnapshotService(
Substitute.For<Microsoft.Extensions.Logging.ILogger<TimePlanningPictureSnapshotService>>(),
_logger,
TimePlanningPnDbContext,
_userService,
_localizationService,
Expand Down Expand Up @@ -73,8 +76,10 @@ public async Task Create_CreatesPictureSnapshot_WithoutFile()
Assert.That(result.Success, Is.False);
}

// SQL/420_SDK.sql seeds s3Enabled = False, so the SDK has no S3 client and the
// upload fails without a network call (SDK 10.0.39+ no longer swallows it).
[Test]
public async Task Create_CreatesPictureSnapshot_WithFile()
public async Task Create_ReturnsFailureAndSavesNoSnapshot_WhenFileUploadFails()
{
// Arrange
var planRegistration = new PlanRegistration
Expand Down Expand Up @@ -110,8 +115,21 @@ public async Task Create_CreatesPictureSnapshot_WithFile()

// Act
var result = await _pictureSnapshotService.Create(model, mockFile, null);

// Assert
Assert.That(result.Success, Is.True);
Assert.That(result.Success, Is.False);
Assert.That(
await TimePlanningPnDbContext.PictureSnapshots.CountAsync(x => x.PlanRegistrationId == planRegistration.Id),
Is.EqualTo(0),
"a snapshot row must not point at a file that was never stored");
// The upload itself failed for lack of an S3 client, not an earlier lookup;
// a real S3 call would fail with an AmazonS3Exception instead.
_logger.Received(1).Log(
Microsoft.Extensions.Logging.LogLevel.Error,
Arg.Any<Microsoft.Extensions.Logging.EventId>(),
Arg.Any<Arg.AnyType>(),
Arg.Is<Exception>(e => e is InvalidOperationException),
Arg.Any<Func<Arg.AnyType, Exception, string>>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ CREATE TABLE `Settings` (

LOCK TABLES `Settings` WRITE;
/*!40000 ALTER TABLE `Settings` DISABLE KEYS */;
INSERT INTO `Settings` VALUES (1,'firstRunDone','true',NULL,NULL,NULL,0),(2,'logLevel','4',NULL,NULL,NULL,0),(3,'logLimit','25000',NULL,NULL,NULL,0),(4,'knownSitesDone','true',NULL,NULL,NULL,0),(5,'fileLocationPicture','/var/www/microting/eform-angular-frontend/eFormAPI/eFormAPI.Web/out/output/datafolder/picture/',NULL,NULL,NULL,0),(6,'fileLocationPdf','/var/www/microting/eform-angular-frontend/eFormAPI/eFormAPI.Web/out/output/datafolder/pdf/',NULL,NULL,NULL,0),(7,'fileLocationJasper','/var/www/microting/eform-angular-frontend/eFormAPI/eFormAPI.Web/out/output/datafolder/reports/',NULL,NULL,NULL,0),(8,'token','abc1234567890abc1234567890abcdef',NULL,NULL,NULL,0),(9,'comAddressBasic','https://basic.microting.com',NULL,NULL,NULL,0),(10,'comAddressApi','https://srv05.microting.com',NULL,NULL,NULL,0),(11,'comAddressPdfUpload','https://srv16.microting.com',NULL,NULL,NULL,0),(12,'comOrganizationId','420',NULL,NULL,NULL,0),(13,'awsAccessKeyId','asdasd',NULL,NULL,NULL,0),(14,'awsSecretAccessKey','asdasd',NULL,NULL,NULL,0),(15,'awsEndPoint','https://sqs.eu-central-1.amazonaws.com/941181150686/',NULL,NULL,NULL,0),(16,'unitLicenseNumber','100',NULL,NULL,NULL,0),(17,'httpServerAddress','http://localhost',NULL,NULL,NULL,0),(18,'maxParallelism','1',NULL,NULL,NULL,0),(19,'numberOfWorkers','1',NULL,NULL,NULL,0),(20,'comSpeechToText','https://speechtotext.microting.com',NULL,NULL,NULL,0),(21,'swiftEnabled','False',NULL,NULL,NULL,0),(22,'swiftUserName','eformsdk',NULL,NULL,NULL,0),(23,'swiftPassword','eformsdktosecretpassword',NULL,NULL,NULL,0),(24,'swiftEndPoint','http://172.16.4.4:8080/swift/v1',NULL,NULL,NULL,0),(25,'keystoneEndPoint','http://172.16.4.4:5000/v2.0',NULL,NULL,NULL,0),(26,'customerNo','420','',NULL,NULL,0),(27,'s3Enabled','True',NULL,NULL,NULL,0),(28,'s3AccessKeyId','asdasd',NULL,NULL,NULL,0),(29,'s3SecrectAccessKey','asdasd',NULL,NULL,NULL,0),(30,'s3Endpoint','https://s3.eu-central-1.amazonaws.com',NULL,NULL,NULL,0),(31,'s3BucketName','microting-uploaded-data',NULL,NULL,NULL,0),(32,'rabbitMqUser','admin',NULL,NULL,NULL,0),(33,'rabbitMqPassword','password',NULL,NULL,NULL,0),(34,'rabbitMqHost','localhost',NULL,NULL,NULL,0),(35,'translationsMigrated','4.0',NULL,NULL,NULL,0),(36,'pluginsEnabled','none',NULL,NULL,NULL,0),(37,'servicesEnabled','none',NULL,NULL,NULL,0),(38,'comAddressNewApi','none',NULL,NULL,NULL,0);
INSERT INTO `Settings` VALUES (1,'firstRunDone','true',NULL,NULL,NULL,0),(2,'logLevel','4',NULL,NULL,NULL,0),(3,'logLimit','25000',NULL,NULL,NULL,0),(4,'knownSitesDone','true',NULL,NULL,NULL,0),(5,'fileLocationPicture','/var/www/microting/eform-angular-frontend/eFormAPI/eFormAPI.Web/out/output/datafolder/picture/',NULL,NULL,NULL,0),(6,'fileLocationPdf','/var/www/microting/eform-angular-frontend/eFormAPI/eFormAPI.Web/out/output/datafolder/pdf/',NULL,NULL,NULL,0),(7,'fileLocationJasper','/var/www/microting/eform-angular-frontend/eFormAPI/eFormAPI.Web/out/output/datafolder/reports/',NULL,NULL,NULL,0),(8,'token','abc1234567890abc1234567890abcdef',NULL,NULL,NULL,0),(9,'comAddressBasic','https://basic.microting.com',NULL,NULL,NULL,0),(10,'comAddressApi','https://srv05.microting.com',NULL,NULL,NULL,0),(11,'comAddressPdfUpload','https://srv16.microting.com',NULL,NULL,NULL,0),(12,'comOrganizationId','420',NULL,NULL,NULL,0),(13,'awsAccessKeyId','asdasd',NULL,NULL,NULL,0),(14,'awsSecretAccessKey','asdasd',NULL,NULL,NULL,0),(15,'awsEndPoint','https://sqs.eu-central-1.amazonaws.com/941181150686/',NULL,NULL,NULL,0),(16,'unitLicenseNumber','100',NULL,NULL,NULL,0),(17,'httpServerAddress','http://localhost',NULL,NULL,NULL,0),(18,'maxParallelism','1',NULL,NULL,NULL,0),(19,'numberOfWorkers','1',NULL,NULL,NULL,0),(20,'comSpeechToText','https://speechtotext.microting.com',NULL,NULL,NULL,0),(21,'swiftEnabled','False',NULL,NULL,NULL,0),(22,'swiftUserName','eformsdk',NULL,NULL,NULL,0),(23,'swiftPassword','eformsdktosecretpassword',NULL,NULL,NULL,0),(24,'swiftEndPoint','http://172.16.4.4:8080/swift/v1',NULL,NULL,NULL,0),(25,'keystoneEndPoint','http://172.16.4.4:5000/v2.0',NULL,NULL,NULL,0),(26,'customerNo','420','',NULL,NULL,0),(27,'s3Enabled','False',NULL,NULL,NULL,0),(28,'s3AccessKeyId','asdasd',NULL,NULL,NULL,0),(29,'s3SecrectAccessKey','asdasd',NULL,NULL,NULL,0),(30,'s3Endpoint','https://s3.eu-central-1.amazonaws.com',NULL,NULL,NULL,0),(31,'s3BucketName','microting-uploaded-data',NULL,NULL,NULL,0),(32,'rabbitMqUser','admin',NULL,NULL,NULL,0),(33,'rabbitMqPassword','password',NULL,NULL,NULL,0),(34,'rabbitMqHost','localhost',NULL,NULL,NULL,0),(35,'translationsMigrated','4.0',NULL,NULL,NULL,0),(36,'pluginsEnabled','none',NULL,NULL,NULL,0),(37,'servicesEnabled','none',NULL,NULL,NULL,0),(38,'comAddressNewApi','none',NULL,NULL,NULL,0);
/*!40000 ALTER TABLE `Settings` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down
Loading