Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed Dec 9, 2024
1 parent d6729db commit db02cd8
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 89 deletions.
4 changes: 3 additions & 1 deletion apps/api/src/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ export const authRoutes =
},
legacyProfiles:
// Include the legacy profiles if a legacy migration has not occurred.
env.USER_MIGRATION_ENABLED && legacyProfiles.length > 1 && !finalProfile.legacyProfileMigratedAt
env.USER_MIGRATION_ENABLED &&
legacyProfiles.length > 1 &&
!finalProfile.legacyProfileMigratedAt
? legacyProfiles
: [],
});
Expand Down
1 change: 0 additions & 1 deletion apps/api/src/routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
} from "../utils/error";
import {
checkCanMigrateLegacyUser,
clearLegacyUser,
createUserProfileBannerUrl,
createUserProfilePictureUrl,
migrateLegacyUser,
Expand Down
48 changes: 0 additions & 48 deletions apps/api/src/utils/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { beforeEach, describe, expect, it } from "vitest";

import {
checkCanMigrateLegacyUser,
clearLegacyUser,
migrateLegacyUser,
parseThirdwebUserLinkedAccounts,
} from "./user";
Expand Down Expand Up @@ -149,23 +148,6 @@ describe("user migration utils", () => {
return legacyProfile;
};

const expectLegacyProfileCleared = async (id: string) => {
const legacyProfile = await db.userProfile.findUnique({
where: { id },
});
expect(!legacyProfile);

const notificationSettings = await db.userNotificationSettings.findMany({
where: { legacyUserProfileId: id },
});
expect(notificationSettings.length).toBe(0);

const socialAccounts = await db.userSocialAccount.findMany({
where: { legacyUserProfileId: id },
});
expect(socialAccounts.length).toBe(0);
};

beforeEach(async () => {
await truncateTables();
});
Expand All @@ -179,9 +161,6 @@ describe("user migration utils", () => {
},
});
const legacyProfile = await createLegacyUserProfile();
const legacyProfile2 = await createLegacyUserProfile({
legacyAddress: EXTERNAL_WALLET_ADDRESS2,
});

const canMigrateResult = await checkCanMigrateLegacyUser({
db,
Expand All @@ -204,16 +183,11 @@ describe("user migration utils", () => {
expect(migrateResult.updatedProfile.tag).toBe("rappzulaLegacy");
expect(migrateResult.updatedSocialAccounts.length).not.toBe(0);
expect(migrateResult.updatedNotificationSettings.length).not.toBe(0);
expectLegacyProfileCleared(legacyProfile.id);
expectLegacyProfileCleared(legacyProfile2.id);
});

it("should connect legacy profile to user", async () => {
const user = await createEcosystemWalletUser();
const legacyProfile = await createLegacyUserProfile();
const legacyProfile2 = await createLegacyUserProfile({
legacyAddress: EXTERNAL_WALLET_ADDRESS2,
});

const canMigrateResult = await checkCanMigrateLegacyUser({
db,
Expand All @@ -235,28 +209,6 @@ describe("user migration utils", () => {
expect(migrateResult.updatedProfile.tag).toBe("rappzulaLegacy");
expect(migrateResult.updatedSocialAccounts.length).not.toBe(0);
expect(migrateResult.updatedNotificationSettings.length).not.toBe(0);
expectLegacyProfileCleared(legacyProfile2.id);
});

it("should clear legacy profile", async () => {
const user = await createEcosystemWalletUser();
const legacyProfile = await createLegacyUserProfile();
const legacyProfile2 = await createLegacyUserProfile({
legacyAddress: EXTERNAL_WALLET_ADDRESS2,
});

const canMigrateResult = await checkCanMigrateLegacyUser({
db,
userId: user.id,
emailAddresses: [],
externalWalletAddresses: [EXTERNAL_WALLET_ADDRESS],
legacyProfileId: legacyProfile.id,
});
expect(canMigrateResult.canMigrate).toBe(true);

await clearLegacyUser({ db, legacyProfile });
expectLegacyProfileCleared(legacyProfile.id);
expectLegacyProfileCleared(legacyProfile2.id);
});

it("should not migrate legacy profile", async () => {
Expand Down
39 changes: 0 additions & 39 deletions apps/api/src/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,42 +385,3 @@ export const migrateLegacyUser = async ({
updatedNotificationSettings,
};
};

export const clearLegacyUser = async ({
db,
legacyProfile,
}: {
db: PrismaClient;
legacyProfile: UserProfile;
}) =>
Promise.all([
// Delete social accounts associated with this legacy profile
db.userSocialAccount.deleteMany({
where: {
legacyUserProfileId: legacyProfile.id,
},
}),
// Delete notification settings associated with this legacy profile
db.userNotificationSettings.deleteMany({
where: {
legacyUserProfileId: legacyProfile.id,
},
}),
// Delete all legacy records
db.$transaction([
db.userProfile.deleteMany({
where: {
legacyAddress: legacyProfile.legacyAddress,
},
}),
...(legacyProfile.email
? []
: [
db.userProfile.deleteMany({
where: {
legacyEmail: legacyProfile.legacyEmail,
},
}),
]),
]),
]);

0 comments on commit db02cd8

Please sign in to comment.