-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat(rest): added filters to getAllCredentials #166
feat(rest): added filters to getAllCredentials #166
Conversation
Codecov Report
@@ Coverage Diff @@
## main #166 +/- ##
==========================================
- Coverage 86.24% 86.15% -0.09%
==========================================
Files 21 21
Lines 1163 1163
Branches 260 257 -3
==========================================
- Hits 1003 1002 -1
- Misses 146 147 +1
Partials 14 14
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: Jim Ezesinachi <jim@animo.id>
Signed-off-by: Jim Ezesinachi <jim@animo.id>
73a89a4
to
4239ec4
Compare
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.
Awesome. Tested locally and it works good! Left some notes on how to make it a bit more efficient when working with large amounts of records
public async getAllCredentials( | ||
@Query('threadId') threadId?: string, | ||
@Query('connectionId') connectionId?: string, | ||
@Query('state') state?: string, |
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.
Does it work if we use CredentialState
as the type here? Maybe that'll give better validation and documentation in the swagger ui?
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.
let credentials = await this.agent.credentials.getAll() | ||
|
||
if (state) credentials = credentials.filter((c) => c.state === state) | ||
if (threadId) credentials = credentials.filter((c) => c.threadId === threadId) |
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.
Ah I see this is also done like this in the connections controller, but we should actually filter in the query, to not retrieve records that aren't needed.
We should expose this in AFJ (I'll create an issue for this), but for now we can do it like this:
const credentialRepository = this.agent.dependencyManager.resolve(CredentialRepository)
const credentials = await credentialRepository.findByQuery({
connectionId,
threadId,
state,
})
return credentials.map((c) => c.toJSON())
When this is merged, could you also make a PR to update this for the connections controller?
@janrtvld FYI
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.
@@ -39,6 +39,48 @@ describe('CredentialController', () => { | |||
}) | |||
}) | |||
|
|||
describe('Get all credentials by state', () => { | |||
test('should return all credentials', async () => { |
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.
As we mock the results, we aren't testing whether te query is correctly applied here.
I think we should spy on the credential repository and see if it was called with the correct parameters:
describe('Get all credentials by state', () => {
test('should return all credentials', async () => {
const credentialRepository = bobAgent.dependencyManager.resolve(CredentialRepository)
const findByQuerySpy = jest.spyOn(credentialRepository, 'findByQuery').mockResolvedValueOnce([testCredential])
const response = await request(app).get('/credentials').query({ state: testCredential.state })
expect(findByQuerySpy).toBeCalledWith({
state: testCredential.state,
})
expect(response.statusCode).toBe(200)
expect(response.body).toEqual([testCredential].map(objectToJson))
})
})
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.
Got it! I'll make the changes now
Signed-off-by: Jim Ezesinachi <jim@animo.id>
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.
🚀 🚀 🚀
Signed-off-by: Jim Ezesinachi <jim@animo.id>
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.
🚀
DCO is failing for some commits (seems the last two). Can you sign off these commits by following these instructions: https://github.com/hyperledger/aries-rfcs/blob/main/contributing.md#how-to-sign-off-previous-commits? Then I'll merge |
Signed-off-by: Jim Ezesinachi <jim@animo.id>
Signed-off-by: Jim Ezesinachi <jim@animo.id>
90f1899
to
e0e4031
Compare
No description provided.