Skip to content

Commit

Permalink
feat: unit test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Oct 16, 2023
1 parent 2898f94 commit adaf602
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 10 deletions.
25 changes: 23 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-10-05T17:10:25.655Z\n"
"PO-Revision-Date: 2023-10-05T17:10:25.655Z\n"
"POT-Creation-Date: 2023-10-16T05:31:23.485Z\n"
"PO-Revision-Date: 2023-10-16T05:31:23.485Z\n"

msgid "WHO privacy policy"
msgstr ""
Expand All @@ -23,6 +23,27 @@ msgstr ""
msgid "Search"
msgstr ""

msgid "Create New Survey"
msgstr ""

msgid "Survey List"
msgstr ""

msgid "Start Date"
msgstr ""

msgid "Status"
msgstr ""

msgid "Survey Type"
msgstr ""

msgid "Assigned Org Unit"
msgstr ""

msgid "Action"
msgstr ""

msgid "Profile"
msgstr ""

Expand Down
2 changes: 2 additions & 0 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GetAllModulesUseCase } from "./domain/usecases/GetAllModulesUseCase";
import { ModuleRepository } from "./domain/repositories/ModuleRepository";
import { ModuleD2Repository } from "./data/repositories/ModuleD2Repository";
import { DataStoreClient } from "./data/DataStoreClient";
import { ModulesTestRepository } from "./data/repositories/testRepositories/ModuleTestRepository";

export type CompositionRoot = ReturnType<typeof getCompositionRoot>;

Expand Down Expand Up @@ -57,6 +58,7 @@ export function getTestCompositionRoot() {
const repositories: Repositories = {
usersRepository: new UserTestRepository(),
localeRepository: new LocalesTestRepository(),
moduleRepository: new ModulesTestRepository(),
};

return getCompositionRoot(repositories);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Future } from "../../../domain/entities/generic/Future";
import { LocalesRepository } from "../../../domain/repositories/LocalesRepository";
import { LocalesType } from "../../../domain/usecases/GetDatabaseLocalesUseCase";
import { FutureData } from "../../api-futures";

export class LocalesTestRepository implements LocalesRepository {
getUiLocales(): FutureData<LocalesType> {
throw new Error("Method not implemented.");
return Future.success([{ locale: "EN", name: "English" }]);
}

getDatabaseLocales(): FutureData<LocalesType> {
throw new Error("Method not implemented.");
return Future.success([{ locale: "EN", name: "English" }]);
}
}
11 changes: 11 additions & 0 deletions src/data/repositories/testRepositories/ModuleTestRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AMRSurveyModule } from "../../../domain/entities/AMRSurveyModule";
import { Future } from "../../../domain/entities/generic/Future";
import { createModuleList } from "../../../domain/entities/__tests__/moduleFixtures";
import { ModuleRepository } from "../../../domain/repositories/ModuleRepository";
import { FutureData } from "../../api-futures";

export class ModulesTestRepository implements ModuleRepository {
getAll(): FutureData<AMRSurveyModule[]> {
return Future.success(createModuleList());
}
}
10 changes: 8 additions & 2 deletions src/data/repositories/testRepositories/UserTestRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import { FutureData } from "../../api-futures";

export class UserTestRepository implements UserRepository {
saveLocale(isUiLocale: boolean, locale: string): FutureData<void> {
throw new Error("Method not implemented.");
if (locale) return Future.success(undefined);
else
return Future.error({
name: "ERR",
message: `Error occurred on saving new locale settings: isUiLocale: ${isUiLocale}, locale: ${locale}`,
});
}
public getCurrent(): FutureData<User> {
return Future.success(createAdminUser());
}

public savePassword(password: string): FutureData<string> {
return Future.success("");
if (password) return Future.success("");
else return Future.error({ name: "ERR", message: "Error occurred on saving new password" });
}
}
4 changes: 2 additions & 2 deletions src/domain/entities/AMRSurveyModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export type SURVEY_TYPE = "NationalSurvey" | "HospitalSurvey" | "SupranationalSu
export interface SurveyProgram extends NamedRef {
type: SURVEY_TYPE;
}
type UserGroups = NamedRef;
type UserGroups = { captureAccess: NamedRef[]; readAccess: NamedRef[] };

export interface AMRSurveyModule {
id: string;
name: string;
color: string;
surveyPrograms: SurveyProgram[];
usergroups: UserGroups[];
userGroups: UserGroups;
}
8 changes: 8 additions & 0 deletions src/domain/entities/__tests__/User.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ describe("User", () => {

expect(user.belongToUserGroup(nonExistedUserGroupId)).toBe(false);
});

// it("should save a new password successfully", () => {
// const newPassword = "district2";

// const user = createUserWithGroups();

// expect(user.belongToUserGroup(nonExistedUserGroupId)).toBe(false);
// });
});
78 changes: 78 additions & 0 deletions src/domain/entities/__tests__/moduleFixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { AMRSurveyModule } from "../AMRSurveyModule";

export function createModuleList(): AMRSurveyModule[] {
return [
{
color: "#A6228F",
id: "ER1eGzQetqt",
name: "Point Prevalence Survey",
surveyPrograms: [
{
id: "SiUPBRxBvSS",
name: "PPS Country Questionnaire",
type: "NationalSurvey",
},
{
id: "Kimo6Gb1Lxu",
name: "PPS Hospital Form",
type: "HospitalSurvey",
},
{
id: "ukcTasHwgdG",
name: "PPS Patient Register",
type: "SupranationalSurvey",
},
{
id: "iwwz8Xssua2",
name: "PPS Survey Form",
type: "NationalSurvey",
},
{
id: "WWeEoX0pfYL",
name: "PPS Ward Register",
type: "SupranationalSurvey",
},
],
userGroups: {
captureAccess: [
{
id: "",
name: "",
},
],
readAccess: [
{
id: "",
name: "",
},
],
},
},
{
color: "#E23A75",
id: "BwJDlAxZTOj",
name: "Prevalence",
surveyPrograms: [
{
id: "i9nXRCg5eWd",
name: "Sneha's Test Event Program",
type: "NationalSurvey",
},
],
userGroups: {
captureAccess: [
{
id: "",
name: "",
},
],
readAccess: [
{
id: "",
name: "",
},
],
},
},
];
}
7 changes: 5 additions & 2 deletions src/webapp/components/survey/SurveyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ interface SurveyListProps {
}

export const SurveyList: React.FC<SurveyListProps> = ({ type }) => {
const { surveys, setSurveys } = {
const {
surveys,
// setSurveys
} = {
surveys: {
kind: "loaded",
data: [
Expand All @@ -35,7 +38,7 @@ export const SurveyList: React.FC<SurveyListProps> = ({ type }) => {
},
],
},
setSurveys: () => {},
// setSurveys: () => {},
};

return (
Expand Down

0 comments on commit adaf602

Please sign in to comment.