-
Notifications
You must be signed in to change notification settings - Fork 83
feat: add signerAddress prop to DELETE subscriptions endpoint #2651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks legit, but left some small comments :)
@@ -203,4 +203,146 @@ describe('DeleteAllSubscriptionsDtoSchema', () => { | |||
}, | |||
]); | |||
}); | |||
|
|||
it('should validate signerAddress when provided', () => { | |||
const deleteAllSubscriptionsDto = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: you could use the builder and only provide the signerAddress
on demand
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('should validate when signerAddress is not provided', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the very first test checks the same, so maybe we dont need it, or should be more explicit in a check
|
||
it('should checksum signerAddress when provided', () => { | ||
const nonChecksummedAddress = faker.finance.ethereumAddress().toLowerCase(); | ||
const deleteAllSubscriptionsDto = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: maybe we could use builder everywhere instead of specifying the whole obj?
@@ -10,6 +10,7 @@ export const DeleteAllSubscriptionsDtoSchema = z.object({ | |||
chainId: NumericStringSchema, | |||
deviceUuid: UuidSchema, | |||
safeAddress: AddressSchema, | |||
signerAddress: AddressSchema.nullable().optional(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be replaced with nullish()
- it is an equivalent
signer_address: signerAddress, | ||
}); | ||
|
||
const deleteAllSubscriptionsDto = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we please also use the builder in these tests
|
||
it('Should include signerAddress in where conditions when provided', async () => { | ||
const signerAddress = getAddress(faker.finance.ethereumAddress()); | ||
const deleteAllSubscriptionsDto = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builder ? :)
}, | ||
}; | ||
|
||
// Handle signerAddress: undefined (omitted) vs null (explicit) vs string (specific address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be simplified:
return subscription.signerAddress === undefined
? baseCondition
: {
...baseCondition,
signer_address:
subscription.signerAddress === null
? IsNull()
: subscription.signerAddress,
};
And maybe we can leave one comment before describing all cases in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @LucieFaire, Thanks for the suggestion, but I'm going to resist it for as long as I can :D
I don't think that nested ternaries make the code simpler. They make it more compact, but sacrifice readibility.
@compojoom I marked it as a draft since the tests are failing. Please feel free to mark it as ready for review once the tests are fixed. thanks |
src/domain/notifications/v2/notifications.repository.integration.spec.ts
Outdated
Show resolved
Hide resolved
src/domain/notifications/v2/notifications.repository.integration.spec.ts
Outdated
Show resolved
Hide resolved
); | ||
|
||
// The subscription with signerAddress1 should still exist | ||
const remainingSubscriptions = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We can rename it to otherSubscriptions
for more readability, Specially that the previous test also has const remainingSubscriptions
and expect it to be zero.
src/domain/notifications/v2/entities/__tests__/delete-all-subscriptions.dto.builder.ts
Outdated
Show resolved
Hide resolved
type: 'string', | ||
required: false, | ||
nullable: true, | ||
description: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thorough explanation. 👏
Summary
Resolves https://linear.app/safe-global/issue/COR-336/expose-signeraddress-to-the-delete-subscriptions-endpoint
adds a signerAddress prop to the delete subscriptions endpoint. This allows us to delete just a single signerAddress.
With this change the endpoint behaves as follows