diff --git a/src/api/services/process/processService.test.ts b/src/api/services/process/processService.test.ts index baad156..9d71218 100644 --- a/src/api/services/process/processService.test.ts +++ b/src/api/services/process/processService.test.ts @@ -5,9 +5,9 @@ import { createProcessService } from "./processService"; const processService = createProcessService(mockConfig); -test("initialize members correctly", () => { +test("initialize members", () => { // Act - const result = processService.analyzeMemberInfo(mockMembers, []); + const result = processService.getMembers(mockMembers, []); // Assert expect(result.length).toBe(mockMembers.length); @@ -21,9 +21,9 @@ test("initialize members correctly", () => { }); }); -test("processService should calculate submissions and progress correctly", () => { +test("calculate submissions and progress", () => { // Act - const result = processService.analyzeMemberInfo(mockMembers, mockSubmissions); + const result = processService.getMembers(mockMembers, mockSubmissions); // Assert const algoInfo = result.find((m) => m.id === "algo")!; // 2 @@ -34,7 +34,7 @@ test("processService should calculate submissions and progress correctly", () => expect(daleInfo.progress).toBe(25); // 1/4 * 100 }); -test("processService should handle duplicate problem submissions", () => { +test("remove duplicate problem submissions", () => { // Arrange const duplicateSubmissions = [ { @@ -50,17 +50,14 @@ test("processService should handle duplicate problem submissions", () => { ]; // Act - const result = processService.analyzeMemberInfo( - mockMembers, - duplicateSubmissions, - ); + const result = processService.getMembers(mockMembers, duplicateSubmissions); // Assert const algo = result.find((m) => m.id === "algo")!; expect(algo.solvedProblems.length).toBe(1); // duplicates should be ignored }); -test("processService should assign correct grades based on submissions", () => { +test("assign correct grades based on submissions", () => { // Arrange const submissions = [ // algo @@ -72,7 +69,7 @@ test("processService should assign correct grades based on submissions", () => { ]; // Act - const result = processService.analyzeMemberInfo(mockMembers, submissions); + const result = processService.getMembers(mockMembers, submissions); // Assert const algoInfo = result.find((m) => m.id === "algo")!; @@ -83,7 +80,7 @@ test("processService should assign correct grades based on submissions", () => { expect(daleInfo.grade).toBe(Grades.SPROUT); // large or equal to 1 }); -test("processService should calculate correct progress percentages", () => { +test("calculate correct progress percentages", () => { // Arrange const submissions = Array.from({ length: 4 }, (_, i) => ({ memberId: "algo", @@ -92,7 +89,7 @@ test("processService should calculate correct progress percentages", () => { })); // Act - const result = processService.analyzeMemberInfo(mockMembers, submissions); + const result = processService.getMembers(mockMembers, submissions); // Assert const algoInfo = result.find((m) => m.id === "algo")!; diff --git a/src/api/services/process/processService.ts b/src/api/services/process/processService.ts index 3a6fd15..b13f22f 100644 --- a/src/api/services/process/processService.ts +++ b/src/api/services/process/processService.ts @@ -4,10 +4,7 @@ import type { Member, MemberIdentity, Submission } from "../common/types"; export function createProcessService(config: Config) { return { - analyzeMemberInfo( - members: MemberIdentity[], - submissions: Submission[], - ): Member[] { + getMembers(members: MemberIdentity[], submissions: Submission[]): Member[] { const memberMap = initializeMemberMap(members); updateSubmissions(memberMap, submissions); diff --git a/src/api/services/store/storeService.test.ts b/src/api/services/store/storeService.test.ts index e8da266..2f36c9a 100644 --- a/src/api/services/store/storeService.test.ts +++ b/src/api/services/store/storeService.test.ts @@ -7,7 +7,7 @@ import { getMembers } from "./storeService"; // Mock services const mockFetchMembers = vi.fn(); const mockFetchSubmissions = vi.fn(); -const mockAnalyzeMemberInfo = vi.fn(); +const mockGetMembers = vi.fn(); vi.mock("../fetch/fetchService"); vi.mocked(createFetchService).mockReturnValue({ @@ -17,7 +17,7 @@ vi.mocked(createFetchService).mockReturnValue({ vi.mock("../process/processService"); vi.mocked(createProcessService).mockReturnValue({ - analyzeMemberInfo: mockAnalyzeMemberInfo, + getMembers: mockGetMembers, }); beforeEach(() => { @@ -25,21 +25,21 @@ beforeEach(() => { mockFetchMembers.mockResolvedValue([]); mockFetchSubmissions.mockResolvedValue([]); - mockAnalyzeMemberInfo.mockReturnValue(mockMembers); + mockGetMembers.mockReturnValue(mockMembers); }); -test("should fetch and process data correctly", async () => { +test("fetch and process data", async () => { // Act const result = await getMembers(); // Assert expect(mockFetchMembers).toHaveBeenCalledTimes(1); expect(mockFetchSubmissions).toHaveBeenCalledTimes(1); - expect(mockAnalyzeMemberInfo).toHaveBeenCalledTimes(1); + expect(mockGetMembers).toHaveBeenCalledTimes(1); expect(result).toEqual(mockMembers); }); -test("getMembers should throw error when fetch fails", async () => { +test("getMembers throws error when fetch fails", async () => { // Arrange mockFetchMembers.mockRejectedValue(new Error("Fetch failed")); @@ -47,9 +47,9 @@ test("getMembers should throw error when fetch fails", async () => { await expect(getMembers()).rejects.toThrow("Fetch failed"); }); -test("getMembers should handle process service errors", async () => { +test("getMembers handles process service errors", async () => { // Arrange - mockAnalyzeMemberInfo.mockImplementation(() => { + mockGetMembers.mockImplementation(() => { throw new Error("Process failed"); }); @@ -57,7 +57,7 @@ test("getMembers should handle process service errors", async () => { await expect(getMembers()).rejects.toThrow("Process failed"); }); -test("getMembers should pass correct parameters to process service", async () => { +test("getMembers called with correct parameters to process service", async () => { // Arrange const mockMembers = [{ id: "1", name: "Test" }]; const mockSubmissions = [{ id: "1", score: 100 }]; @@ -68,8 +68,5 @@ test("getMembers should pass correct parameters to process service", async () => await getMembers(); // Assert - expect(mockAnalyzeMemberInfo).toHaveBeenCalledWith( - mockMembers, - mockSubmissions, - ); + expect(mockGetMembers).toHaveBeenCalledWith(mockMembers, mockSubmissions); }); diff --git a/src/api/services/store/storeService.ts b/src/api/services/store/storeService.ts index c2b4180..fe36c3e 100644 --- a/src/api/services/store/storeService.ts +++ b/src/api/services/store/storeService.ts @@ -7,10 +7,10 @@ export async function getMembers(): Promise { const fetchService = createFetchService(CONFIG); const processService = createProcessService(CONFIG); - const [members, submissions] = await Promise.all([ + const [memberIdentities, submissions] = await Promise.all([ fetchService.fetchMembers(), fetchService.fetchSubmissions(CONFIG.study.repository), ]); - return processService.analyzeMemberInfo(members, submissions); + return processService.getMembers(memberIdentities, submissions); }