Skip to content

Commit

Permalink
feat: minimize fields in user profile (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujank2050 committed Mar 28, 2023
1 parent 025430a commit 5e234c0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
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

0 comments on commit 5e234c0

Please sign in to comment.