From 801baa5d518ff0f34b5f9c1bd75971554c018559 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 12 May 2026 02:35:38 +0530 Subject: [PATCH] Completed CommBank tasks --- CommBank-Web | 1 + codelabs/1_backend.md | 2 +- codelabs/2_frontend.md | 22 ++++++++++++++++------ tasks/4_tests/cover_get_for_user.md | 27 +++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 9 deletions(-) create mode 160000 CommBank-Web diff --git a/CommBank-Web b/CommBank-Web new file mode 160000 index 0000000..73f96cf --- /dev/null +++ b/CommBank-Web @@ -0,0 +1 @@ +Subproject commit 73f96cf7b0643bed424ba8dcd837ae1e26d4dfcc diff --git a/codelabs/1_backend.md b/codelabs/1_backend.md index 01516fb..5b1f33e 100644 --- a/codelabs/1_backend.md +++ b/codelabs/1_backend.md @@ -123,7 +123,7 @@ using MongoDB.Driver; namespace CommBank.Services; -public class GoalsService : IGoalsService +public sService : IGoalsService { private readonly IMongoCollection _goalsCollection; diff --git a/codelabs/2_frontend.md b/codelabs/2_frontend.md index 1fa0c5f..d1885f2 100644 --- a/codelabs/2_frontend.md +++ b/codelabs/2_frontend.md @@ -83,12 +83,22 @@ export function GoalManager(props: Props) { const hasIcon = () => icon != null const pickEmojiOnClick = (emoji: BaseEmoji, event: MouseEvent) => { - // TODO(stop event propogation) - // TODO(set icon locally) - // TODO(close emoji picker) - // TODO(create updated goal) - // TODO(update store) - // TODO(update database) + const pickEmojiOnClick = (emoji: BaseEmoji, event: MouseEvent) => { + event.stopPropagation() + + setIcon(emoji.native) + setEmojiPickerIsOpen(false) + + const updatedGoal: Goal = { + ...props.goal, + icon: emoji.native ?? props.goal.icon, + name: name ?? props.goal.name, + targetDate: targetDate ?? props.goal.targetDate, + targetAmount: targetAmount ?? props.goal.targetAmount, + } + + dispatch(updateGoalRedux(updatedGoal)) +} } return ( diff --git a/tasks/4_tests/cover_get_for_user.md b/tasks/4_tests/cover_get_for_user.md index 03313ca..c14b00e 100644 --- a/tasks/4_tests/cover_get_for_user.md +++ b/tasks/4_tests/cover_get_for_user.md @@ -19,9 +19,32 @@ public class GoalControllerTests // ... - [Fact] - public async void GetForUser() + [Fact] +public async void GetForUser() +{ + // Arrange + var goals = collections.GetGoals(); + var users = collections.GetUsers(); + IGoalsService goalsService = new FakeGoalsService(goals, goals[0]); + IUsersService usersService = new FakeUsersService(users, users[0]); + GoalController controller = new(goalsService, usersService); + + // Act + var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext(); + controller.ControllerContext.HttpContext = httpContext; + var result = await controller.GetForUser(goals[0].UserId!); + + // Assert + Assert.NotNull(result); + + var index = 0; + foreach (Goal goal in result!) { + Assert.IsAssignableFrom(goal); + Assert.Equal(goals[0].UserId, goal.UserId); + index++; + } +} // Arrange var goals = collections.GetGoals(); var users = collections.GetUsers();