-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started writing api tests for establishment
docker image for the db has gone out of date with the dev database can't really progress here until we make a decision on how to sync them
- Loading branch information
1 parent
3aa7483
commit dfcecd0
Showing
2 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
TramsDataApi.Test/Integration/V4/EstablishmentV4IntegrationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using AutoFixture; | ||
using Dfe.Academies.Contracts.V4.Establishments; | ||
using Dfe.Academies.Domain.Establishment; | ||
using FluentAssertions; | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace TramsDataApi.Test.Integration.V4 | ||
{ | ||
[Collection("Database")] | ||
public class EstablishmentV4IntegrationTests : IClassFixture<TramsDataApiFactory> | ||
{ | ||
private readonly HttpClient _client; | ||
private static readonly Fixture _autoFixture = new Fixture(); | ||
private readonly TramsDataApiFactory _apiFixture; | ||
|
||
private readonly string _apiUrlPrefix = "https://trams-api.com/v4"; | ||
|
||
public EstablishmentV4IntegrationTests(TramsDataApiFactory apiFixture) | ||
{ | ||
_apiFixture = apiFixture; | ||
_client = _apiFixture.CreateClient(); | ||
_client.DefaultRequestHeaders.Add("ApiKey", "testing-api-key"); | ||
_client.BaseAddress = new Uri(_apiUrlPrefix); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_EstablishmentByUkPrn_NoEstablishmentExists_Returns_NotFound() | ||
{ | ||
var ukPrn = _autoFixture.Create<int>(); | ||
var getEstablishmentResponse = await _client.GetAsync($"/establishment/{ukPrn}"); | ||
getEstablishmentResponse.StatusCode.Should().Be(HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_EstablishmentByUkPrn_EstablishmentExists_Returns_Ok() | ||
{ | ||
using var context = _apiFixture.GetMstrContext(); | ||
|
||
var establishment = new Establishment(); | ||
establishment.LocalAuthority = null; | ||
establishment.UKPRN = _autoFixture.Create<string>(); | ||
establishment.FK_LocalAuthority = 1; | ||
|
||
context.Establishments.Add(establishment); | ||
context.SaveChanges(); | ||
|
||
var getEstablishmentResponse = await _client.GetAsync($"/establishment/{establishment.UKPRN}"); | ||
getEstablishmentResponse.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
var establishmentContent = await getEstablishmentResponse.Content.ReadFromJsonAsync<EstablishmentDto>(); | ||
|
||
// "ukprn": "string", | ||
// "urn": "string", | ||
// "name": "string", | ||
// "localAuthorityCode": "string", | ||
// "localAuthorityName": "string", | ||
// "ofstedRating": "string", | ||
// "ofstedLastInspection": "string", | ||
// "statutoryLowAge": "string", | ||
// "statutoryHighAge": "string", | ||
// "schoolCapacity": "string", | ||
// "pfi": "string", | ||
// "establishmentNumber": "string", | ||
// "pan": "string", | ||
// "deficit": "string", | ||
// "viabilityIssue": "string", | ||
// "giasLastChangedDate": "string", | ||
// "noOfBoys": "string", | ||
// "noOfGirls": "string", | ||
// "senUnitCapacity": "string", | ||
// "senUnitOnRoll": "string", | ||
// "religousEthos": "string", | ||
// "headteacherTitle": "string", | ||
// "headteacherFirstName": "string", | ||
// "headteacherLastName": "string", | ||
// "headteacherPreferredJobTitle": "string", | ||
|
||
establishmentContent.Ukprn.Should().Be(establishment.UKPRN); | ||
establishmentContent.Urn.Should().Be(establishment.URN.ToString()); | ||
establishmentContent.Name.Should().Be(establishment.EstablishmentName); | ||
establishmentContent.LocalAuthorityCode.Should().Be(establishment.LocalAuthority.Code); | ||
establishmentContent.LocalAuthorityName.Should().Be(establishment.LocalAuthority.Name); | ||
|
||
} | ||
} | ||
} |