Skip to content

Commit

Permalink
api: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
biwano committed Nov 30, 2023
1 parent 3aac5fe commit bbd7e0b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 35 deletions.
2 changes: 1 addition & 1 deletion carbonmark-api/src/routes/users/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const handler = (fastify: FastifyInstance) =>

const listings = user?.listings?.map(formatListing) || [];

const response = {
const response: User = {
createdAt: profile?.createdAt || 0,
description: profile?.description || "", // TODO extract to nullable `profile` property.
handle: profile?.handle || "",
Expand Down
22 changes: 0 additions & 22 deletions carbonmark-api/src/utils/helpers/users.utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { app } from "firebase-admin";
import { chunk } from "lodash";
import { Activity } from "../../models/Activity.model";
import { Asset } from "../../models/Asset.model";
import { Listing } from "../../models/Listing.model";
import { User } from "../../models/User.model";

export interface UserProfile {
address: string;
Expand Down Expand Up @@ -91,21 +87,3 @@ const formatProfile = (profile: UserProfile): UserProfile => {
updatedAt: Math.floor(profile.updatedAt / 1000),
};
};

export const userFromProfile = (
profile: UserProfile,
props: { listings: Listing[]; activities: Activity[]; assets: Asset[] }
): User => {
return {
createdAt: profile?.createdAt || 0,
description: profile?.description || "", // TODO extract to nullable `profile` property.
handle: profile?.handle || "",
profileImgUrl: profile?.profileImgUrl || null,
updatedAt: profile?.updatedAt || 0,
username: profile?.username || "",
wallet: profile.address,
listings: props.listings,
activities: props.activities,
assets: props.assets,
};
};
1 change: 1 addition & 0 deletions carbonmark-api/test/fixtures/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const listing = aListing({
totalAmountToSell: "100000000000000000000",
leftToSell: "100000000000000000000",
updatedAt: "1234",
createdAt: "1234",
});

const projectWithListing = aProject({
Expand Down
22 changes: 12 additions & 10 deletions carbonmark-api/test/routes/projects/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,18 @@ describe("GET /projects", () => {
price: "99",
updatedAt: marketplace.projectWithListing.listings?.[0].updatedAt,
listings: [
pick(marketplace.projectWithListing.listings![0], [
"active",
"batchPrices",
"batches",
"createdAt",
"deleted",
"updatedAt",
"id",
"tokenAddress",
]),
{
...pick(marketplace.projectWithListing.listings![0], [
"active",
"batchPrices",
"batches",
"deleted",
"id",
"tokenAddress",
]),
createdAt: 1234,
updatedAt: 1234,
},
],
location: {
geometry: {
Expand Down
4 changes: 2 additions & 2 deletions carbonmark-api/test/test.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const MOCK_USER_PROFILE: UserProfile = {

export const EXPECTED_USER_RESPONSE = {
...omit(MOCK_USER_PROFILE, ["address", "updatedAt", "createdAt"]),
updatedAt: "1699715108",
createdAt: "0",
updatedAt: 1699715108,
createdAt: 0,
wallet: MOCK_USER_PROFILE.address,
listings: [],
activities: [],
Expand Down

0 comments on commit bbd7e0b

Please sign in to comment.