Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new sem dom api #1735

Merged
merged 33 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
babb8e5
Revert "Revert "Semantic domain model/type update (#1718)" (#1732)"
jasonleenaylor Sep 19, 2022
5d74142
WIP: Get Backend API squared away
jasonleenaylor Sep 6, 2022
36c41c2
Open API regenerated
jasonleenaylor Sep 6, 2022
e37ca25
WIP: Still working over the api and the front-end changes
jasonleenaylor Sep 6, 2022
8da9a88
Prettify files
jasonleenaylor Sep 8, 2022
d4f4461
WIP: Calling the backend for the full semantic domain info
jasonleenaylor Sep 8, 2022
7dc8542
Get tree root from backend
jasonleenaylor Sep 9, 2022
34aa6d5
Backend cleanup
imnasnainaec Sep 9, 2022
f7364cd
More backend clean-up & handle 'null' for parent
jasonleenaylor Sep 9, 2022
ed20f0b
Add fetching of full semantic domains on completed tree navigation
jasonleenaylor Sep 12, 2022
b8e8cb0
Start fixing frontend unit tests
jasonleenaylor Sep 12, 2022
d3b0206
Fix race condition exposed in TreeSearch tests
jasonleenaylor Sep 14, 2022
74fa527
Fix TreeViewActions tests
jasonleenaylor Sep 14, 2022
cd98fc9
Clean-up test data for domain tree
jasonleenaylor Sep 15, 2022
c4fae75
Simplify TreeViewHeader and fix more test data
jasonleenaylor Sep 16, 2022
9790d96
Fix some more tests
jasonleenaylor Sep 16, 2022
470bec3
Update snapshots and update Root depiction
jasonleenaylor Sep 19, 2022
503ffb5
Fix LGTM errors
jasonleenaylor Sep 20, 2022
0cd4405
Respond to review comments
jasonleenaylor Sep 20, 2022
3134caa
More commit Clean-up
jasonleenaylor Sep 26, 2022
d85c402
Respond to code review comments
jasonleenaylor Sep 30, 2022
7013b04
One more code review response
jasonleenaylor Sep 30, 2022
820ca39
Fix formatting of new test assertions
jasonleenaylor Sep 30, 2022
a29711a
Merge branch 'master' into UseNewSemDomApi
imnasnainaec Oct 4, 2022
5e75191
Distinguish TreeNode more
imnasnainaec Oct 4, 2022
2021305
Don't force 'en' domain search; Remove unused import
imnasnainaec Oct 4, 2022
0fe9e75
Merge branch 'master' into UseNewSemDomApi
imnasnainaec Oct 13, 2022
d1c2dac
Import: Add MongoID on each SemanticDomain
imnasnainaec Oct 14, 2022
0d47aab
Import test: Add check for empty MongoId
imnasnainaec Oct 14, 2022
a6734fd
Merge branch 'master' into UseNewSemDomApi
imnasnainaec Oct 14, 2022
e34be01
Clone MongoId when cloning SemanticDomain
imnasnainaec Oct 14, 2022
9ea1dcd
Update comments
imnasnainaec Oct 14, 2022
09dc770
Cleanup frontend tree search
imnasnainaec Oct 14, 2022
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
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ docs/user_guide/site

# Ignore generated JavaScript for Release info
public/scripts/release.js

# Ignore semantic domain import files (valid for mongo but not valid json)
deploy/scripts/semantic_domains/json/*.json
database/semantic_domains/*
2 changes: 1 addition & 1 deletion Backend.Tests/Controllers/AvatarControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Setup()
_permissionService = new PermissionServiceMock(_userRepo);
_avatarController = new AvatarController(_userRepo, _permissionService)
{
// Mock the Http Context because this isn't an actual call avatar controller
// Mock the Http Context because this isn't an actual call controller
ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }
};
_userController = new UserController(
Expand Down
6 changes: 6 additions & 0 deletions Backend.Tests/Controllers/LiftControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ public void TestRoundtrip(RoundTripObj roundTripObj)
}
}

// Assert that the first SemanticDomain doesn't have an empty MongoId.
if (allWords[0].Senses.Count > 0 && allWords[0].Senses[0].SemanticDomains.Count > 0)
{
Assert.IsNotEmpty(allWords[0].Senses[0].SemanticDomains[0].MongoId);
}

// Export.
var exportedFilePath = _liftController.CreateLiftExport(proj1.Id).Result;
var exportedDirectory = FileOperations.ExtractZipFile(exportedFilePath, null);
Expand Down
19 changes: 2 additions & 17 deletions Backend.Tests/Controllers/ProjectControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using BackendFramework.Controllers;
using BackendFramework.Interfaces;
using BackendFramework.Models;
using BackendFramework.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;
Expand All @@ -17,7 +16,6 @@ public class ProjectControllerTests
private IUserRepository _userRepo = null!;
private UserRoleRepositoryMock _userRoleRepo = null!;
private IPermissionService _permissionService = null!;
private ISemanticDomainService _semDomService = null!;
private ProjectController _projController = null!;

private User _jwtAuthenticatedUser = null!;
Expand All @@ -29,11 +27,9 @@ public void Setup()
_userRepo = new UserRepositoryMock();
_userRoleRepo = new UserRoleRepositoryMock();
_permissionService = new PermissionServiceMock(_userRepo);
_semDomService = new SemanticDomainService();
_projController = new ProjectController(_projRepo, _semDomService, _userRoleRepo,
_userRepo, _permissionService)
_projController = new ProjectController(_projRepo, _userRoleRepo, _userRepo, _permissionService)
{
// Mock the Http Context because this isn't an actual call avatar controller
// Mock the Http Context because this isn't an actual call controller
ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }
};

Expand Down Expand Up @@ -115,17 +111,6 @@ public void TestDeleteAllProjects()
Assert.That(_projRepo.GetAllProjects().Result, Has.Count.EqualTo(0));
}

[Test]
public void TestParseSemanticDomains()
{
var project = _projRepo.Create(Util.RandomProject()).Result;
var sdList = (List<SemanticDomainWithSubdomains>)(
(ObjectResult)_projController.GetSemDoms(project!.Id).Result).Value!;
Assert.That(sdList, Has.Count.EqualTo(3));
Assert.That(sdList[0].Subdomains, Has.Count.EqualTo(3));
Assert.That(sdList[0].Subdomains[0].Subdomains, Has.Count.EqualTo(3));
}

[Test]
public void TestProjectDuplicateCheck()
{
Expand Down
90 changes: 90 additions & 0 deletions Backend.Tests/Controllers/SemanticDomainControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Backend.Tests.Mocks;
using BackendFramework.Controllers;
using BackendFramework.Interfaces;
using BackendFramework.Models;
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;

namespace Backend.Tests.Controllers
{
public class SemanticDomainControllerTests
{
private ISemanticDomainRepository _semDomRepository = null!;
private SemanticDomainController _semDomController = null!;

private const string Id = "1";
private const string Lang = "en";
private const string Name = "Universe";

private readonly SemanticDomainFull _semDom = new() { Id = Id, Lang = Lang, Name = Name };

[SetUp]
public void Setup()
{
_semDomRepository = new SemanticDomainRepositoryMock();
_semDomController = new SemanticDomainController(_semDomRepository);
}

[Test]
public void SemanticDomainController_GetSemanticDomainFull_DomainFound()
{
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(_semDom);
var domain = (SemanticDomainFull?)(
(ObjectResult)_semDomController.GetSemanticDomainFull(Id, Lang).Result).Value;
Assert.That(domain?.Id, Is.EqualTo(Id));
Assert.That(domain?.Lang, Is.EqualTo(Lang));
Assert.That(domain?.Name, Is.EqualTo(Name));
}

[Test]
public void SemanticDomainController_GetSemanticDomainFull_DomainNotFound()
{
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(null);
var domain = (SemanticDomainFull?)(
(ObjectResult)_semDomController.GetSemanticDomainFull(Id, Lang).Result).Value;
Assert.That(domain, Is.Null);
}

[Test]
public void SemanticDomainController_GetSemanticDomainTreeNode_DomainFound()
{
var treeNode = new SemanticDomainTreeNode(_semDom);
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(treeNode);
var domain = (SemanticDomainTreeNode?)(
(ObjectResult)_semDomController.GetSemanticDomainTreeNode(Id, Lang).Result).Value;
Assert.That(domain?.Id, Is.EqualTo(Id));
Assert.That(domain?.Lang, Is.EqualTo(Lang));
Assert.That(domain?.Name, Is.EqualTo(Name));
}

[Test]
public void SemanticDomainController_GetSemanticDomainTreeNode_DomainNotFound()
{
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(null);
var domain = (SemanticDomainTreeNode?)(
(ObjectResult)_semDomController.GetSemanticDomainTreeNode(Id, Lang).Result).Value;
Assert.That(domain, Is.Null);
}

[Test]
public void SemanticDomainController_GetSemanticDomainTreeNodeByName_DomainFound()
{
var treeNode = new SemanticDomainTreeNode(_semDom);
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(treeNode);
var domain = (SemanticDomainTreeNode?)(
(ObjectResult)_semDomController.GetSemanticDomainTreeNodeByName(Name, Lang).Result).Value;
Assert.That(domain?.Id, Is.EqualTo(Id));
Assert.That(domain?.Lang, Is.EqualTo(Lang));
Assert.That(domain?.Name, Is.EqualTo(Name));
}

[Test]
public void SemanticDomainController_GetSemanticDomainTreeNodeByName_DomainNotFound()
{
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(null);
var domain = (SemanticDomainTreeNode?)(
(ObjectResult)_semDomController.GetSemanticDomainTreeNodeByName(Name, Lang).Result).Value;
Assert.That(domain, Is.Null);
}
}
}
31 changes: 31 additions & 0 deletions Backend.Tests/Mocks/SemanticDomainRepositoryMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Threading.Tasks;
using BackendFramework.Interfaces;
using BackendFramework.Models;

namespace Backend.Tests.Mocks
{
public class SemanticDomainRepositoryMock : ISemanticDomainRepository
{
private object? _responseObj;

public Task<SemanticDomainFull?> GetSemanticDomainFull(string id, string lang)
{
return Task.FromResult((SemanticDomainFull?)_responseObj);
}

public Task<SemanticDomainTreeNode?> GetSemanticDomainTreeNode(string id, string lang)
{
return Task.FromResult((SemanticDomainTreeNode?)_responseObj);
}

public Task<SemanticDomainTreeNode?> GetSemanticDomainTreeNodeByName(string name, string lang)
{
return Task.FromResult((SemanticDomainTreeNode?)_responseObj);
}

internal void SetNextResponse(object? response)
{
_responseObj = response;
}
}
}
2 changes: 1 addition & 1 deletion Backend.Tests/Models/ProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void TestClone()
{
var system = new WritingSystem { Name = "WritingSystemName", Bcp47 = "en", Font = "calibri" };
var project = new Project { Name = "ProjectName", VernacularWritingSystem = system };
var domain = new SemanticDomain { Name = "SemanticDomainName", Id = "1", Description = "text" };
var domain = new SemanticDomain { Name = "SemanticDomainName", Id = "1" };
project.SemanticDomains.Add(domain);

var customField = new CustomField { Name = "CustomFieldName", Type = "type" };
Expand Down
88 changes: 88 additions & 0 deletions Backend.Tests/Models/SemanticDomainTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using BackendFramework.Models;
using NUnit.Framework;

namespace Backend.Tests.Models
{
public class SemanticDomainTests
{
private const string Name = "Home";

[Test]
public void TestEquals()
{
var domain = new SemanticDomain { Name = Name };
Assert.That(domain.Equals(new SemanticDomain { Name = Name }));
}

[Test]
public void TestEqualsNull()
{
var domain = new SemanticDomain { Name = Name };
Assert.IsFalse(domain.Equals(null));
}

[Test]
public void TestHashCode()
{
Assert.AreNotEqual(
new SemanticDomain { Id = "1" }.GetHashCode(),
new SemanticDomain { Id = "2" }.GetHashCode()
);

Assert.AreNotEqual(
new SemanticDomain { Name = "1" }.GetHashCode(),
new SemanticDomain { Name = "2" }.GetHashCode()
);

Assert.AreNotEqual(
new SemanticDomain { Guid = Guid.NewGuid().ToString() }.GetHashCode(),
new SemanticDomain { Name = Guid.NewGuid().ToString() }.GetHashCode()
);
}
}

public class SemanticDomainFullTests
{
private const string Name = "Home";

[Test]
public void TestEquals()
{
var domain = new SemanticDomainFull { Name = Name };
Assert.That(domain.Equals(new SemanticDomainFull { Name = Name }));
}

[Test]
public void TestEqualsNull()
{
var domain = new SemanticDomainFull { Name = Name };
Assert.IsFalse(domain.Equals(null));
}

[Test]
public void TestHashCode()
{
Assert.AreNotEqual(
new SemanticDomainFull { Id = "1" }.GetHashCode(),
new SemanticDomainFull { Id = "2" }.GetHashCode()
);

Assert.AreNotEqual(
new SemanticDomainFull { Name = "1" }.GetHashCode(),
new SemanticDomainFull { Name = "2" }.GetHashCode()
);

Assert.AreNotEqual(
new SemanticDomainFull { Description = "1" }.GetHashCode(),
new SemanticDomainFull { Description = "2" }.GetHashCode()
);

Assert.AreNotEqual(
new SemanticDomainFull { Questions = new List<string> { "1" } }.GetHashCode(),
new SemanticDomainFull { Questions = new List<string> { "2" } }.GetHashCode()
);
}
}
}
19 changes: 0 additions & 19 deletions Backend.Tests/Models/WordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,23 +433,4 @@ public void TestHashCode()
);
}
}

public class SemanticDomainTests
{
private const string Name = "Home";

[Test]
public void TestEquals()
{
var domain = new SemanticDomain { Name = Name };
Assert.That(domain.Equals(new SemanticDomain { Name = Name }));
}

[Test]
public void TestEqualsNull()
{
var domain = new SemanticDomain { Name = Name };
Assert.IsFalse(domain.Equals(null));
}
}
}
1 change: 0 additions & 1 deletion Backend.Tests/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public static SemanticDomain RandomSemanticDomain(string? id = null)
{
Name = RandString(),
Id = id ?? RandString(),
Description = RandString()
};
}

Expand Down
23 changes: 23 additions & 0 deletions Backend/Contexts/SemanticDomainContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Diagnostics.CodeAnalysis;
using BackendFramework.Interfaces;
using BackendFramework.Models;
using Microsoft.Extensions.Options;
using MongoDB.Driver;

namespace BackendFramework.Contexts
{
[ExcludeFromCodeCoverage]
public class SemanticDomainContext : ISemanticDomainContext
{
private readonly IMongoDatabase _db;

public SemanticDomainContext(IOptions<Startup.Settings> options)
{
var client = new MongoClient(options.Value.ConnectionString);
_db = client.GetDatabase(options.Value.CombineDatabase);
}

public IMongoCollection<SemanticDomainTreeNode> SemanticDomains => _db.GetCollection<SemanticDomainTreeNode>("SemanticDomainTree");
public IMongoCollection<SemanticDomainFull> FullSemanticDomains => _db.GetCollection<SemanticDomainFull>("SemanticDomains");
}
}
Loading