|
13 | 13 | using Microsoft.Extensions.Options; |
14 | 14 | using Newtonsoft.Json; |
15 | 15 | using NSubstitute; |
| 16 | +using NSubstitute.ExceptionExtensions; |
16 | 17 | using NUnit.Framework; |
17 | 18 | using SIL.XForge.Configuration; |
18 | 19 | using SIL.XForge.DataAccess; |
@@ -2556,6 +2557,60 @@ await env |
2556 | 2557 | await env.SyncService.DidNotReceive().SyncAsync(Arg.Any<SyncConfig>()); |
2557 | 2558 | } |
2558 | 2559 |
|
| 2560 | + [Test] |
| 2561 | + public async Task UpdateSettingsAsync_ChangeAlternateTrainingSource_AnotherUserOnTheProjectCannotRefreshToken() |
| 2562 | + { |
| 2563 | + var env = new TestEnvironment(); |
| 2564 | + const string newProjectParatextId = "changedId"; |
| 2565 | + env.ParatextService.TryGetProjectRoleAsync( |
| 2566 | + Arg.Is<UserSecret>(u => u.Id == User02), |
| 2567 | + newProjectParatextId, |
| 2568 | + CancellationToken.None |
| 2569 | + ) |
| 2570 | + .ThrowsAsync(new UnauthorizedAccessException()); |
| 2571 | + |
| 2572 | + // Ensure that the new project does not exist |
| 2573 | + Assert.That( |
| 2574 | + env.RealtimeService.GetRepository<SFProject>().Query().Any(p => p.ParatextId == newProjectParatextId), |
| 2575 | + Is.False |
| 2576 | + ); |
| 2577 | + |
| 2578 | + // SUT |
| 2579 | + await env.Service.UpdateSettingsAsync( |
| 2580 | + User01, |
| 2581 | + Project01, |
| 2582 | + new SFProjectSettings { AlternateTrainingSourceParatextId = newProjectParatextId } |
| 2583 | + ); |
| 2584 | + |
| 2585 | + // Verify the alternate training source property of the target project |
| 2586 | + SFProject project = env.GetProject(Project01); |
| 2587 | + Assert.That(project.TranslateConfig.DraftConfig.AlternateTrainingSource?.ProjectRef, Is.Not.Null); |
| 2588 | + Assert.That( |
| 2589 | + project.TranslateConfig.DraftConfig.AlternateTrainingSource?.ParatextId, |
| 2590 | + Is.EqualTo(newProjectParatextId) |
| 2591 | + ); |
| 2592 | + Assert.That(project.TranslateConfig.DraftConfig.AlternateTrainingSource?.Name, Is.EqualTo("NewSource")); |
| 2593 | + Assert.That(project.UserRoles, Contains.Key(User02)); |
| 2594 | + |
| 2595 | + // Verify the project document that was created for the alternate training source |
| 2596 | + SFProject alternateTrainingSourceProject = env.GetProject( |
| 2597 | + project.TranslateConfig.DraftConfig.AlternateTrainingSource!.ProjectRef |
| 2598 | + ); |
| 2599 | + Assert.That(alternateTrainingSourceProject.ParatextId, Is.EqualTo(newProjectParatextId)); |
| 2600 | + Assert.That(alternateTrainingSourceProject.Name, Is.EqualTo("NewSource")); |
| 2601 | + Assert.That(alternateTrainingSourceProject.UserRoles, Does.Not.ContainKey(User02)); |
| 2602 | + |
| 2603 | + // Verify that a sync is scheduled |
| 2604 | + await env.SyncService.Received().SyncAsync(Arg.Any<SyncConfig>()); |
| 2605 | + env.BackgroundJobClient.Received(1).Create(Arg.Any<Job>(), Arg.Any<IState>()); |
| 2606 | + |
| 2607 | + // Verify that the alternate training source project was created |
| 2608 | + Assert.That( |
| 2609 | + env.RealtimeService.GetRepository<SFProject>().Query().Any(p => p.ParatextId == newProjectParatextId), |
| 2610 | + Is.True |
| 2611 | + ); |
| 2612 | + } |
| 2613 | + |
2559 | 2614 | [Test] |
2560 | 2615 | public async Task UpdateSettingsAsync_ChangeAdditionalTrainingSource_CreatesProject() |
2561 | 2616 | { |
|
0 commit comments