Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: minimize fields in user profile #276

Merged
merged 7 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/user/src/__test__/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module "../../types" {
interface UserProfile {
givenName: string;
surname: string;
}
}

export { type UserProfile } from "../../types";
6 changes: 6 additions & 0 deletions packages/user/src/__test__/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export const getFakeData = ():
surname: "Smith",
});

export const getPartialFakeData = ():
| UserProfileCreateInput
| UserProfileUpdateInput => ({
id: getFakeId(),
});

export const getLimitAndOffsetDataset = async (
count: number,
config: ApiConfig
Expand Down
23 changes: 21 additions & 2 deletions packages/user/src/__test__/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { describe, expect, it, vi } from "vitest";

import createConfig from "./helpers/createConfig";
import { createDatabase, removeExtraSpace } from "./helpers/createDatabase";
import { getFakeData, getLimitAndOffsetDataset } from "./helpers/utils";
import {
getFakeData,
getLimitAndOffsetDataset,
getPartialFakeData,
} from "./helpers/utils";
import UserService from "../model/user-profiles/service";

import type { Mock } from "vitest";
Expand All @@ -15,7 +19,7 @@ describe("UserProfile Service", () => {
const config = createConfig();
const service = new UserService(config, createDatabase(queryValue));

it("should create a new user profile instance", async () => {
it("should create a new user profile instance with augmented fields", async () => {
// test "create" method
const data = getFakeData();
await service.create(data);
Expand All @@ -28,6 +32,21 @@ describe("UserProfile Service", () => {
);
});

it("should create a new user profile instance with partial field", async () => {
// test "create" method
const data = getPartialFakeData();
await service.create(data);

const query = service.factory.getCreateSql(data);

expect(query.values).toHaveLength(1);

expect(queryValue).toHaveBeenCalledWith(
removeExtraSpace(query.sql),
query.values
);
});

it("should find correct correct user profile", async () => {
// test "findById" method
await service.findById(10);
Expand Down
5 changes: 1 addition & 4 deletions packages/user/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ interface PasswordErrorMessages {
}

interface UserProfile {
givenName: string;
id: string;
middleNames?: string;
surname?: string;
}

type UserProfileCreateInput = Omit<UserProfile, "id">;
type UserProfileCreateInput = Partial<UserProfile>;

type UserProfileUpdateInput = Partial<Omit<UserProfile, "id">>;

Expand Down