Skip to content

Commit

Permalink
fix: use the formal framework parent org
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Metsu authored and CumpsD committed Feb 7, 2020
1 parent bbe33d3 commit 56ed2ec
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ public static IEnumerable<FormalFrameworkOrganisationBase> Map(
if (formalFrameworks == null || !formalFrameworks.Any())
continue;

formalFrameworkOrganisations.Add(new FormalFrameworkOrganisationBase(document, @params, DateTime.Now));
formalFrameworkOrganisations.Add(
new FormalFrameworkOrganisationBase(
document,
@params,
formalFrameworkId,
DateTime.Now));
}

return formalFrameworkOrganisations;
Expand Down Expand Up @@ -122,6 +127,7 @@ public static IEnumerable<FormalFrameworkOrganisationExtended> MapExtended(
new FormalFrameworkOrganisationExtended(
document,
@params,
formalFrameworkId,
today));
}

Expand Down Expand Up @@ -216,17 +222,19 @@ public class FormalFrameworkOrganisationBase
public FormalFrameworkOrganisationBase(
OrganisationDocument document,
ApiConfiguration @params,
Guid formalFrameworkId,
DateTime today)
{
var parent = document
.Parents?
.FirstOrDefault(
x => x.Validity == null ||
var formalFramework = document.FormalFrameworks
?.Single(
x =>
x.FormalFrameworkId == formalFrameworkId &&
(x.Validity == null ||
(!x.Validity.Start.HasValue || x.Validity.Start.Value <= today) &&
(!x.Validity.End.HasValue || x.Validity.End.Value >= today));
(!x.Validity.End.HasValue || x.Validity.End.Value >= today)));

ParentOrganisationId = parent?.ParentOrganisationId;
ParentOrganisationName = parent?.ParentOrganisationName;
ParentOrganisationId = formalFramework?.ParentOrganisationId;
ParentOrganisationName = formalFramework?.ParentOrganisationName;

OrganisationId = document.Id;
OrganisationName = document.Name;
Expand Down Expand Up @@ -323,8 +331,9 @@ public class FormalFrameworkOrganisationExtended : FormalFrameworkOrganisationBa
public FormalFrameworkOrganisationExtended(
OrganisationDocument document,
ApiConfiguration @params,
Guid formalFrameworkId,
DateTime today)
: base(document, @params, today)
: base(document, @params, formalFrameworkId, today)
{
INR = document.Keys
?.FirstOrDefault(x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ public void HasTheCurrentMinister()
OrganisationClassifications = new List<OrganisationDocument.OrganisationOrganisationClassification>
{
new OrganisationDocument.OrganisationOrganisationClassification(
Guid.NewGuid(),
responsibleMinisterClassificationTypeId,
"Responsible Minister",
Guid.NewGuid(),
"Not the current minister",
new Period(currentlyInactiveDate, currentlyInactiveDate)),
organisationOrganisationClassificationId: Guid.NewGuid(),
organisationClassificationTypeId: responsibleMinisterClassificationTypeId,
organisationClassificationTypeName: "Responsible Minister",
organisationClassificationId: Guid.NewGuid(),
organisationClassificationName: "Not the current minister",
validity: new Period(currentlyInactiveDate, currentlyInactiveDate)),
new OrganisationDocument.OrganisationOrganisationClassification(
Guid.NewGuid(),
responsibleMinisterClassificationTypeId,
"Responsible Minister",
Guid.NewGuid(),
"The current minister",
new Period(currentlyActiveDate, currentlyActiveDate))
organisationOrganisationClassificationId: Guid.NewGuid(),
organisationClassificationTypeId: responsibleMinisterClassificationTypeId,
organisationClassificationTypeName: "Responsible Minister",
organisationClassificationId: Guid.NewGuid(),
organisationClassificationName: "The current minister",
validity: new Period(currentlyActiveDate, currentlyActiveDate))
}
};
var apiConfiguration = new ApiConfiguration
Expand All @@ -48,12 +48,68 @@ public void HasTheCurrentMinister()
var formalFrameworkOrganisationBase =
new FormalFrameworkOrganisationBase(
organisationDocument,
apiConfiguration, DateTime.Today);
apiConfiguration,
Guid.NewGuid(),
DateTime.Today);

formalFrameworkOrganisationBase
.ResponsibleMinister
.Should()
.Be("The current minister");
}

[Fact]
public void ShowsTheParentOrgOfTheFormalFramework()
{
var currentlyActiveDate = DateTime.Today;

var responsibleMinisterClassificationTypeId = Guid.NewGuid();

var parentOrganisationId = Guid.NewGuid();
var formalFrameworkId = Guid.NewGuid();
var organisationDocument = new OrganisationDocument
{
FormalFrameworks = new List<OrganisationDocument.OrganisationFormalFramework>
{
new OrganisationDocument.OrganisationFormalFramework(
organisationFormalFrameworkId: Guid.NewGuid(),
formalFrameworkId: Guid.NewGuid(),
formalFrameworkName: "FormalFrameworkName",
parentOrganisationId: Guid.NewGuid(),
parentOrganisationName: "parentOrganisationName",
validity: new Period(currentlyActiveDate, currentlyActiveDate)),
new OrganisationDocument.OrganisationFormalFramework(
organisationFormalFrameworkId: Guid.NewGuid(),
formalFrameworkId: formalFrameworkId,
formalFrameworkName: "FormalFrameworkName",
parentOrganisationId: parentOrganisationId,
parentOrganisationName: "The Actual ParentOrganisationName",
validity: new Period(currentlyActiveDate, currentlyActiveDate))
}
};
var apiConfiguration = new ApiConfiguration
{
ResponsibleMinisterClassificationTypeId = responsibleMinisterClassificationTypeId,
DataVlaanderenOrganisationUri = "https://example.com",
};

var formalFrameworkOrganisationBase =
new FormalFrameworkOrganisationBase(
organisationDocument,
apiConfiguration,
formalFrameworkId,
DateTime.Today);

formalFrameworkOrganisationBase
.ParentOrganisationId
.Should()
.Be(parentOrganisationId);

formalFrameworkOrganisationBase
.ParentOrganisationName
.Should()
.Be("The Actual ParentOrganisationName");
}

}
}

0 comments on commit 56ed2ec

Please sign in to comment.