Skip to content

Commit

Permalink
Migrate to Lens v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoginth committed Dec 8, 2024
1 parent 05a68d8 commit a419026
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 38 deletions.
20 changes: 10 additions & 10 deletions apps/api/src/routes/internal/account/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ export const get = [
validateLensAccount,
validateHasCreatorToolsAccess,
async (req: Request, res: Response) => {
const { id } = req.query;
const accountAddress = req.query.address as string;

if (!id) {
if (!accountAddress) {
return noBody(res);
}

try {
const [preference, permissions, email, membershipNft, theme, mutedWords] =
await prisma.$transaction([
prisma.preference.findUnique({ where: { id: id as string } }),
prisma.profilePermission.findMany({
prisma.preference.findUnique({ where: { accountAddress } }),
prisma.accountPermission.findMany({
include: { permission: { select: { key: true } } },
where: { enabled: true, profileId: id as string }
where: { enabled: true, accountAddress }
}),
prisma.email.findUnique({ where: { id: id as string } }),
prisma.membershipNft.findUnique({ where: { id: id as string } }),
prisma.profileTheme.findUnique({ where: { id: id as string } }),
prisma.mutedWord.findMany({ where: { profileId: id as string } })
prisma.email.findUnique({ where: { accountAddress } }),
prisma.membershipNft.findUnique({ where: { accountAddress } }),
prisma.accountTheme.findUnique({ where: { accountAddress } }),
prisma.mutedWord.findMany({ where: { accountAddress } })
]);

const response: InternalAccount = {
Expand All @@ -51,7 +51,7 @@ export const get = [
}))
};

logger.info(`Internal account fetched for ${id}`);
logger.info(`Internal account fetched for ${accountAddress}`);

return res.status(200).json({ result: response, success: true });
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/staff-picks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const get = [
});
}

const accountPermission = await prisma.profilePermission.findMany({
select: { profileId: true },
const accountPermission = await prisma.accountPermission.findMany({
select: { accountAddress: true },
where: { enabled: true, permissionId: PermissionId.StaffPick }
});

Expand Down
2 changes: 1 addition & 1 deletion apps/api/tests/email/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("POST /email/update", () => {
const email = faker.internet.email();
try {
await prisma.email.create({
data: { email, id: TEST_LENS_ID }
data: { email, accountAddress: TEST_LENS_ID }
});
} catch {}

Expand Down
21 changes: 15 additions & 6 deletions apps/api/tests/internal/account/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("GET /internal/account/get", () => {
test("should return 200 and the internal account data", async () => {
const preference = await prisma.preference.create({
data: {
id: faker.string.uuid(),
accountAddress: faker.string.uuid(),
appIcon: 1,
highSignalNotificationFilter: true,
developerMode: true
Expand All @@ -21,22 +21,31 @@ describe("GET /internal/account/get", () => {
const [email] = await Promise.all([
prisma.email.create({
data: {
id: preference.id,
accountAddress: preference.accountAddress,
email: faker.internet.email(),
verified: true
}
}),
prisma.profilePermission.create({
data: { profileId: preference.id, permissionId: PermissionId.Beta }
prisma.accountPermission.create({
data: {
accountAddress: preference.accountAddress,
permissionId: PermissionId.Beta
}
}),
prisma.membershipNft.create({
data: { id: preference.id, dismissedOrMinted: true }
data: {
accountAddress: preference.accountAddress,
dismissedOrMinted: true
}
})
]);

const { data, status } = await axios.get(
`${TEST_URL}/internal/account/get`,
{ params: { id: preference.id }, headers: getTestAuthHeaders() }
{
params: { address: preference.accountAddress },
headers: getTestAuthHeaders()
}
);

expect(status).toBe(200);
Expand Down
8 changes: 4 additions & 4 deletions apps/api/tests/internal/creator-tools/assign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe("POST /internal/creator-tools/assign", () => {
expect(data.success).toBe(true);
expect(data.enabled).toBe(true);

const accountPermission = await prisma.profilePermission.findFirst({
where: { profileId: accountAddress, permissionId }
const accountPermission = await prisma.accountPermission.findFirst({
where: { accountAddress, permissionId }
});
expect(accountPermission).toBeDefined();
});
Expand All @@ -42,8 +42,8 @@ describe("POST /internal/creator-tools/assign", () => {
expect(data.success).toBe(true);
expect(data.enabled).toBe(false);

const accountPermission = await prisma.profilePermission.findFirst({
where: { profileId: accountAddress, permissionId }
const accountPermission = await prisma.accountPermission.findFirst({
where: { accountAddress, permissionId }
});
expect(accountPermission).toBeNull();
});
Expand Down
8 changes: 4 additions & 4 deletions apps/api/tests/internal/permissions/assign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe("POST /internal/permissions/assign", () => {
expect(status).toBe(200);
expect(data.enabled).toBe(true);

const accountPermission = await prisma.profilePermission.findFirst({
where: { profileId: TEST_LENS_ID, permissionId: PermissionId.Beta }
const accountPermission = await prisma.accountPermission.findFirst({
where: { accountAddress: TEST_LENS_ID, permissionId: PermissionId.Beta }
});
expect(accountPermission?.permissionId).toBe(PermissionId.Beta);
});
Expand All @@ -33,8 +33,8 @@ describe("POST /internal/permissions/assign", () => {
expect(status).toBe(200);
expect(data.enabled).toBe(false);

const accountPermission = await prisma.profilePermission.findFirst({
where: { profileId: TEST_LENS_ID, permissionId: PermissionId.Beta }
const accountPermission = await prisma.accountPermission.findFirst({
where: { accountAddress: TEST_LENS_ID, permissionId: PermissionId.Beta }
});
expect(accountPermission).toBeNull();
});
Expand Down
4 changes: 2 additions & 2 deletions apps/api/tests/internal/permissions/bulkAssign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ describe("POST /internal/permissions/bulkAssign", () => {
expect(status).toBe(200);
expect(data.assigned).toBe(testAccountIds.length);

const accountPermissions = await prisma.profilePermission.findMany({
const accountPermissions = await prisma.accountPermission.findMany({
where: {
permissionId: PermissionId.Beta,
profileId: { in: testAccountIds }
accountAddress: { in: testAccountIds }
}
});

Expand Down
20 changes: 12 additions & 8 deletions apps/api/tests/preferences/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,38 @@ describe("GET /preferences/get", () => {

const [, , , permission] = await Promise.all([
prisma.preference.upsert({
where: { id: TEST_LENS_ID },
where: { accountAddress: TEST_LENS_ID },
update: {
appIcon: 2,
highSignalNotificationFilter: true,
developerMode: true
},
create: {
id: TEST_LENS_ID,
accountAddress: TEST_LENS_ID,
appIcon: 2,
highSignalNotificationFilter: true,
developerMode: true
}
}),
prisma.email.upsert({
where: { id: TEST_LENS_ID },
where: { accountAddress: TEST_LENS_ID },
update: { email: testEmail, verified: true },
create: { id: TEST_LENS_ID, email: testEmail, verified: true }
create: {
accountAddress: TEST_LENS_ID,
email: testEmail,
verified: true
}
}),
prisma.membershipNft.upsert({
where: { id: TEST_LENS_ID },
where: { accountAddress: TEST_LENS_ID },
update: { dismissedOrMinted: true },
create: { id: TEST_LENS_ID, dismissedOrMinted: true }
create: { accountAddress: TEST_LENS_ID, dismissedOrMinted: true }
}),
prisma.permission.create({ data: { key: testPermissionKey } })
]);

await prisma.profilePermission.create({
data: { profileId: TEST_LENS_ID, permissionId: permission.id }
await prisma.accountPermission.create({
data: { accountAddress: TEST_LENS_ID, permissionId: permission.id }
});
});

Expand Down
2 changes: 1 addition & 1 deletion apps/api/tests/preferences/updateNftStatus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("POST /preferences/updateNftStatus", () => {
expect(data.result.dismissedOrMinted).toBe(true);

const membershipNft = await prisma.membershipNft.findUnique({
where: { id: TEST_LENS_ID }
where: { accountAddress: TEST_LENS_ID }
});
expect(membershipNft?.dismissedOrMinted).toBe(true);
});
Expand Down

0 comments on commit a419026

Please sign in to comment.