Skip to content

Commit

Permalink
feat: tests of transformer classes
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaugomez committed Jun 27, 2024
1 parent 5979ae4 commit 9ebcca0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/profile/data/collections/profiles-collection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { ProfileDoc } from "@/src/profile/data/collections/profiles-collection";
import { ProfileDocTransformer } from "@/src/profile/data/collections/profiles-collection";
import { ProfileModel } from "@/src/profile/domain/models/profile-model";
import type { WithId } from "mongodb";
import { ObjectId } from "mongodb";
import { describe, expect, it } from "vitest";

describe("ProfileDocTransformer", () => {
it("transforms ProfileDoc to ProfileModel", () => {
const mockProfileDoc: WithId<ProfileDoc> = {
_id: new ObjectId(),
userId: new ObjectId(),
displayName: "Test Profile Name",
handle: "test_user_114",
bio: "Test bio of the profile",
picture: "https://example.com/picture.jpg",
backgroundPicture: "https://example.com/background.jpg",
website: "https://johndoe.com",
isPublic: true,
tags: ["maths", "science", "history", "programming"],
};

const transformer = new ProfileDocTransformer(mockProfileDoc);
const profileModel = transformer.toDomain();

expect(profileModel).toBeInstanceOf(ProfileModel);
expect(profileModel.id).toBe(mockProfileDoc._id.toString());
expect(profileModel.userId).toBe(mockProfileDoc.userId.toString());
expect(profileModel.displayName).toBe(mockProfileDoc.displayName);
expect(profileModel.handle).toBe(mockProfileDoc.handle);
expect(profileModel.bio).toBe(mockProfileDoc.bio);
expect(profileModel.picture).toBe(mockProfileDoc.picture);
expect(profileModel.backgroundPicture).toBe(
mockProfileDoc.backgroundPicture,
);
expect(profileModel.website).toBe(mockProfileDoc.website);
expect(profileModel.isPublic).toBe(mockProfileDoc.isPublic);
expect(profileModel.tags).toEqual(mockProfileDoc.tags);
});
});

0 comments on commit 9ebcca0

Please sign in to comment.