Skip to content

Commit 7465a2a

Browse files
Merge pull request #125 from boolean-uk/233-fullstack---use-real-data-on-search-page
233 fullstack use real data on search page
2 parents 3bc85cd + a09696c commit 7465a2a

File tree

14 files changed

+83
-78
lines changed

14 files changed

+83
-78
lines changed

exercise.tests/IntegrationTests/BaseIntegrationTest.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,25 @@ FROM users u
5656
WHERE u.role = 'student'
5757
GROUP BY u.id, u.email, u.role, u.passwordhash;
5858
*/
59-
protected const string TeacherEmail = "[email protected]"; // has post id 34,35 and comment id 37
60-
protected const string TeacherPassword = "Neidintulling!l33t";
61-
protected const int TeacherId = 160;
59+
protected const string TeacherEmail = "[email protected]";
60+
protected const string TeacherPassword = "lettPassord123!";
61+
protected const string TeacherUsername = "reduan-presley47";
62+
protected const int TeacherId = 47;
6263
protected const int TeacherPostID = 34;
6364
protected const int TeacherCommentID = 37;
64-
65-
protected const string StudentEmail1 = "[email protected]"; //id 232, has post id 57, 58 and comment id 2
66-
protected const string StudentPassword1 = "SuperHash!4";
67-
protected const int StudentId1 = 9;
68-
protected const int StudentPostID1 = 57;
69-
protected const int StudentCommentID1 = 2;
70-
71-
protected const string StudentEmail2 = "[email protected]"; //id 85, has post id 36 and comment id 3
72-
protected const string StudentPassword2 = "Neidintulling!l33t";
73-
protected const int StudentPostID2 = 36;
74-
protected const int StudentCommentID2 = 3;
65+
protected const int TeacherCohort = 37;
66+
67+
protected const string StudentEmail1 = "[email protected]";
68+
protected const string StudentPassword1 = "Timianerkul1!";
69+
protected const int StudentId1 = 7;
70+
protected const int StudentPostID1 = 21;
71+
protected const int StudentCommentID1 = 23;
72+
73+
protected const string StudentEmail2 = "[email protected]";
74+
protected const string StudentPassword2 = "lettPassord123!";
75+
protected const int StudentId2 = 54;
76+
protected const int StudentPostID2 = 24;
77+
protected const int StudentCommentID2 = 46;
7578

7679

7780
protected async Task<string> LoginAndGetToken(string email, string password, bool success = true, bool longlife = false)

exercise.tests/IntegrationTests/CohortTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ public async Task CreateCohort(string email, string password, string cohortName,
269269
[TestCase(TeacherEmail, TeacherPassword, 350, 1, 1, "User with Id 350 not found.", HttpStatusCode.BadRequest)]
270270
[TestCase(TeacherEmail, TeacherPassword, 1, 20, 1, "Cohort with Id 20 not found.", HttpStatusCode.BadRequest)]
271271
[TestCase(TeacherEmail, TeacherPassword, 1, 1, 10, "The specified course is not part of this cohort.", HttpStatusCode.BadRequest)]
272-
[TestCase(TeacherEmail, TeacherPassword, 11, 1, 1, "User is already in the specified course in the cohort.", HttpStatusCode.BadRequest)]
273-
[TestCase(StudentEmail1, StudentPassword1, 1, 1, 1, "You are not authorized to add a user to a cohort.", HttpStatusCode.Forbidden)]
272+
[TestCase(TeacherEmail, TeacherPassword, TeacherId, 3, 3, "User is already in the specified course in the cohort.", HttpStatusCode.BadRequest)]
273+
[TestCase(StudentEmail1, StudentPassword1, 1, 3, 1, "You are not authorized to add a user to a cohort.", HttpStatusCode.Forbidden)]
274274
public async Task AddUserToCohortAndDeleteUser(
275275
string email,
276276
string password,
@@ -392,9 +392,9 @@ public async Task AddUserToCohortAndDeleteUser(
392392

393393
[TestCase(TeacherEmail, TeacherPassword, 350, 1, 1, "User with Id 350 not found.", HttpStatusCode.BadRequest)]
394394
[TestCase(TeacherEmail, TeacherPassword, 1, 20, 1, "Cohort with Id 20 not found.", HttpStatusCode.BadRequest)]
395-
[TestCase(TeacherEmail, TeacherPassword, 11, 1, 10, "The specified course is not part of this cohort.", HttpStatusCode.BadRequest)]
395+
[TestCase(TeacherEmail, TeacherPassword, 11, 3, 10, "The specified course is not part of this cohort.", HttpStatusCode.BadRequest)]
396396
[TestCase(TeacherEmail, TeacherPassword, 1, 1, 1, "The specified user is not part of this cohort.", HttpStatusCode.BadRequest)]
397-
[TestCase(TeacherEmail, TeacherPassword, 11, 1, 2, "User is in cohort, but is not taking the specified course.", HttpStatusCode.BadRequest)]
397+
[TestCase(TeacherEmail, TeacherPassword, 11, 3, 2, "User is in cohort, but is not taking the specified course.", HttpStatusCode.BadRequest)]
398398
[TestCase(StudentEmail1, StudentPassword1, 1, 1, 1, "You are not authorized to delete a user from a cohort.", HttpStatusCode.Forbidden)]
399399
public async Task InvalidDeletes(
400400
string email,

exercise.tests/IntegrationTests/UserTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public async Task UpdateUserUsernameExists()
308308
{
309309
var fieldsToUpdate = new Dictionary<string, object?>
310310
{
311-
{ "username", "nigel-nowak2"}
311+
{ "username", TeacherUsername}
312312
};
313313

314314
var token = await LoginAndGetToken(TeacherEmail, TeacherPassword);
@@ -327,7 +327,7 @@ public async Task UpdateUserGitHubUsernameExists()
327327
{
328328
var fieldsToUpdate = new UserPatchDTO()
329329
{
330-
GithubUsername = "nigel-nowak2"
330+
GithubUsername = TeacherUsername
331331
};
332332

333333
int userId = 13;
@@ -346,7 +346,7 @@ public async Task UpdateUserEmailExists()
346346
{
347347
var fieldsToUpdate = new UserPatchDTO()
348348
{
349-
349+
Email=TeacherEmail
350350
};
351351

352352
int userId = 13;

exercise.tests/IntegrationTests/ValidationTests.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,8 @@ namespace exercise.tests.IntegrationTests
1111
/// <summary>
1212
/// Integration coverage for the validation endpoints, ensuring parity with business rules.
1313
/// </summary>
14-
public class ValidationTests
14+
public class ValidationTests : BaseIntegrationTest
1515
{
16-
private WebApplicationFactory<Program> _factory;
17-
private HttpClient _client;
18-
19-
[SetUp]
20-
public void SetUp()
21-
{
22-
// Arrange
23-
_factory = new WebApplicationFactory<Program>();
24-
_client = _factory.CreateClient();
25-
}
26-
27-
[TearDown]
28-
public void TearDown()
29-
{
30-
_client.Dispose();
31-
_factory.Dispose();
32-
}
33-
3416
/// <summary>
3517
/// Ensures the password validation endpoint surfaces the correct status code per input.
3618
/// </summary>
@@ -218,7 +200,7 @@ public async Task ValidateUsernameMessage(string endpoint, string input, string
218200
/// <param name="input">The username to query.</param>
219201
/// <param name="expectedMessage">The message expected from the API.</param>
220202
/// <param name="expectedStatusCode">The HTTP status code that should be returned.</param>
221-
[TestCase("donald-esposito121", "Username is already in use", HttpStatusCode.BadRequest)]
203+
[TestCase(TeacherUsername, "Username is already in use", HttpStatusCode.BadRequest)]
222204
[TestCase("does-not-exist5", "Accepted", HttpStatusCode.OK)]
223205
public async Task ValidateUsernameExists(string input, string expectedMessage, HttpStatusCode expectedStatusCode)
224206
{
@@ -249,7 +231,7 @@ public async Task ValidateUsernameExists(string input, string expectedMessage, H
249231
/// <param name="input">The GitHub username to query.</param>
250232
/// <param name="expectedMessage">The response message expected.</param>
251233
/// <param name="expectedStatusCode">The HTTP status the endpoint should emit.</param>
252-
[TestCase("donald-esposito121", "GitHub username is already in use", HttpStatusCode.BadRequest)]
234+
[TestCase(TeacherUsername, "GitHub username is already in use", HttpStatusCode.BadRequest)]
253235
[TestCase("does-not-exist5", "Accepted", HttpStatusCode.OK)]
254236
public async Task ValidateGitUsernameExists(string input, string expectedMessage, HttpStatusCode expectedStatusCode)
255237
{
@@ -279,7 +261,7 @@ public async Task ValidateGitUsernameExists(string input, string expectedMessage
279261
/// <param name="input">The email to query.</param>
280262
/// <param name="expectedMessage">The message expected in the response.</param>
281263
/// <param name="expectedStatusCode">The HTTP status the endpoint should emit.</param>
282-
[TestCase("[email protected]", "Email already exists", HttpStatusCode.BadRequest)]
264+
[TestCase(TeacherEmail, "Email already exists", HttpStatusCode.BadRequest)]
283265
[TestCase("[email protected]", "Accepted", HttpStatusCode.OK)]
284266
public async Task ValidateEmailExists(string input, string expectedMessage, HttpStatusCode expectedStatusCode)
285267
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace exercise.wwwapi.DTOs.Cohort
2+
{
3+
public class BasicCohortDTO
4+
{
5+
public int Id { get; set; }
6+
public required string Title { get; init; }
7+
public DateTime StartDate { get; set; }
8+
public DateTime EndDate { get; set; }
9+
}
10+
}

exercise.wwwapi/DTOs/GetUsers/UsersSuccessDTO.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace exercise.wwwapi.DTOs.GetUsers
66
public class UsersSuccessDTO
77
{
88
[JsonPropertyName("users")]
9-
public List<User> Users { get; set; }
9+
public List<UserDTO> Users { get; set; }
1010
}
1111

1212
}

exercise.wwwapi/DTOs/UserDTO.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using exercise.wwwapi.Models;
1+
using exercise.wwwapi.DTOs.Cohort;
2+
using exercise.wwwapi.Models;
23

34
namespace exercise.wwwapi.DTOs
45
{
56
public class UserDTO
67
{
8+
public int Id { get; set; }
79
public string? Username { get; set; }
810
public string? Email { get; set; }
911
public string? FirstName { get; set; }
@@ -13,8 +15,8 @@ public class UserDTO
1315
public Roles? Role { get; set; }
1416
public string? Specialism { get; set; }
1517
public string? Bio { get; set; }
16-
public DateTime? StartDate { get; set; }
17-
public DateTime? EndDate { get; set; }
1818
public string? Photo { get; set; }
19+
public BasicCohortDTO? Cohort { get; set; }
20+
1921
}
2022
}

exercise.wwwapi/DTOs/UserPatchDTO.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public class UserPatchDTO
1212
public int? Role { get; set; }
1313
public string? Specialism { get; set; }
1414
public string? Cohort { get; set; }
15-
public DateTime? StartDate { get; set; }
16-
public DateTime? EndDate { get; set; }
1715
public string? Bio { get; set; }
1816
public string? Photo { get; set; }
1917
}

exercise.wwwapi/Data/CohortCourseData.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace exercise.wwwapi.Data
44
{
55
public class CohortCourseData
66
{
7+
DateTime somedate = new DateTime(2020, 12, 05, 0, 0, 0, DateTimeKind.Utc);
8+
79
private List<string> _courseNames = new List<string>()
810
{
911
"Software Development",
@@ -34,7 +36,10 @@ public CohortCourseData(List<User> users)
3436

3537
for (int x = 0; x < _cohortNames.Count; x++)
3638
{
37-
Cohort cohort = new Cohort() { Id = x+1 , Title = _cohortNames[x] };
39+
Cohort cohort = new Cohort() { Id = x+1 , Title = _cohortNames[x],
40+
StartDate = somedate.AddDays(-random.Next(0, 30)).AddMinutes(random.Next(400, 1200)),
41+
EndDate = somedate.AddDays(random.Next(31, 365)).AddMinutes(random.Next(400, 1200)),
42+
};
3843
_cohorts.Add(cohort);
3944
}
4045

exercise.wwwapi/Data/PersonData.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ public PersonData()
115115
Specialism = specialism,
116116
Role = role,
117117
PasswordHash = password,
118-
StartDate = somedate.AddDays(-userRandom.Next(30, 30)),
119-
EndDate = somedate.AddDays(userRandom.Next(31, 365)),
120118
Photo = photo
121119
};
122120

0 commit comments

Comments
 (0)