-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): finished user class methods and tests
- Loading branch information
1 parent
ce60e7b
commit 549e539
Showing
12 changed files
with
352 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { User } from '../../src/v3/user/user'; | ||
import { activitiesStub, userStub } from '../../test/stubs/v3/user.stub'; | ||
|
||
export const UserMockService = (user: User) => ({ | ||
meMock: jest.spyOn(user.sdk, 'me_query').mockResolvedValue({ | ||
me: userStub(), | ||
}), | ||
getSingleUserMock: jest.spyOn(user.sdk, 'user_query').mockResolvedValue({ | ||
user: userStub(), | ||
}), | ||
myPDACountMock: jest.spyOn(user.sdk, 'myPDACount_query').mockResolvedValue({ | ||
myPDACount: 10, | ||
}), | ||
myPDAsMock: jest.spyOn(user.sdk, 'myPDAs_query').mockResolvedValue({ | ||
myPDAs: userStub().issuedPDAs, | ||
}), | ||
myDataModelsCountMock: jest | ||
.spyOn(user.sdk, 'dataModelsCount_query') | ||
.mockResolvedValue({ | ||
dataModelsCount: 10, | ||
}), | ||
myActivitiesCountMock: jest | ||
.spyOn(user.sdk, 'myActivitiesCount_query') | ||
.mockResolvedValue({ myActivitiesCount: 10 }), | ||
myActivitiesMock: jest | ||
.spyOn(user.sdk, 'myActivities_query') | ||
.mockResolvedValue({ myActivities: activitiesStub() }), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { UserIdentifierTypeV3 } from '../../types'; | ||
import { errorHandler } from '../../utils/errorHandler'; | ||
import { isStringValid } from '../../utils/validators'; | ||
import { | ||
FilterDataModelInput, | ||
myActivities_queryQueryVariables, | ||
myActivitiesCount_queryQueryVariables, | ||
myPDACount_queryQueryVariables, | ||
myPDAs_queryQueryVariables, | ||
Sdk, | ||
} from '../../../gatewaySdk/sources/GatewayV3'; | ||
|
||
export class User { | ||
public sdk: Sdk; | ||
|
||
constructor(sdk: Sdk) { | ||
this.sdk = sdk; | ||
} | ||
|
||
/** | ||
* The function `me` makes an asynchronous call to `me_query` and returns the result, or throws an | ||
* error if something goes wrong. | ||
* @returns a Promise that resolves to me. | ||
*/ | ||
async me() { | ||
try { | ||
return await this.sdk.me_query(); | ||
} catch (error) { | ||
throw new Error(errorHandler(error)); | ||
} | ||
} | ||
|
||
/** | ||
* The function takes a user identifier type and value as input, queries the user using the SDK, and | ||
* returns the result. | ||
* @param - - `type`: The type of user identifier. It can be one of the following values: | ||
* @returns The `user` function is returning the result of the `user_query` method call from the `sdk` | ||
* object. | ||
*/ | ||
async getSingleUser({ | ||
type, | ||
value, | ||
}: { | ||
type: UserIdentifierTypeV3; | ||
value: string; | ||
}) { | ||
try { | ||
isStringValid(value); | ||
return await this.sdk.user_query({ input: { type, value } }); | ||
} catch (error) { | ||
throw new Error(errorHandler(error)); | ||
} | ||
} | ||
|
||
/** | ||
* The function `myPDACount` is an asynchronous function that returns the count of a user's PDA | ||
* based on an optional filter. | ||
* @param {FilterPDAInput} [filter] - The `filter` parameter is an optional input that allows you to | ||
* specify criteria for filtering the PDAs before counting them. It is | ||
* of type `FilterPDAInput`. | ||
* @returns a Promise that resolves to a number. | ||
*/ | ||
async myPDACount(filter?: myPDACount_queryQueryVariables) { | ||
try { | ||
return (await this.sdk.myPDACount_query(filter)).myPDACount; | ||
} catch (error) { | ||
throw new Error(errorHandler(error)); | ||
} | ||
} | ||
|
||
/** | ||
* The function `myPDAs` is an asynchronous function that takes in a `myPDAs_queryQueryVariables` object and returns a | ||
* promise that resolves to a `myPDAs_queryQuery` object. | ||
* @param {myPDAs_queryQueryVariables} - - `filter`: An object that contains filter criteria for the query. | ||
* @returns a Promise that resolves to a value of type `myPDAs_queryQuery`. | ||
*/ | ||
async myPDAs(variables?: myPDAs_queryQueryVariables) { | ||
try { | ||
return await this.sdk.myPDAs_query(variables); | ||
} catch (error) { | ||
throw new Error(errorHandler(error)); | ||
} | ||
} | ||
|
||
/** | ||
* The function `myDataModelsCount` is an asynchronous function that retrieves the count of data | ||
* models based on an optional filter and returns the count. | ||
* @param {FilterDataModelInput} [filter] - The `filter` parameter is an optional input that allows | ||
* you to specify conditions to filter the data models. It is of type `FilterDataModelInput`. You can | ||
* use this parameter to define criteria such as filtering by a specific field value or applying | ||
* logical operators like AND and OR to combine multiple conditions. | ||
* @returns the count of data models that match the provided filter. | ||
*/ | ||
async myDataModelsCount(filter?: FilterDataModelInput) { | ||
try { | ||
return (await this.sdk.dataModelsCount_query({ filter })).dataModelsCount; | ||
} catch (error) { | ||
throw new Error(errorHandler(error)); | ||
} | ||
} | ||
|
||
async myActivities(filter?: myActivities_queryQueryVariables) { | ||
try { | ||
return await this.sdk.myActivities_query(filter); | ||
} catch (error) { | ||
throw new Error(errorHandler(error)); | ||
} | ||
} | ||
|
||
async myActivitiesCount(filter?: myActivitiesCount_queryQueryVariables) { | ||
try { | ||
return (await this.sdk.myActivitiesCount_query(filter)).myActivitiesCount; | ||
} catch (error) { | ||
throw new Error(errorHandler(error)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Activity, User } from '../../../gatewaySdk/sources/GatewayV3'; | ||
|
||
export const userStub = (overrideUser?: Partial<User>): User => ({ | ||
id: 'f47ac10b-58cc-4372-a567-0e02b2c3d479', | ||
createdAt: new Date('2021-01-01T12:00:00Z'), | ||
updatedAt: new Date('2021-01-01T12:00:00Z'), | ||
username: 'test01', | ||
isCompleted: true, | ||
issuedPDAs: [], | ||
receivedPDAs: [], | ||
receivedProofs: [], | ||
recipientDataRequests: [], | ||
verifierDataRequests: [], | ||
roles: [], | ||
did: 'did:gatewayid:abc123', | ||
encryptionKey: '', | ||
usernameLastUpdated: new Date('2021-01-01T12:00:00Z'), | ||
...overrideUser, | ||
}); | ||
|
||
export const activitiesStub = (): Activity[] => { | ||
return [ | ||
{ | ||
action: 'PDA_ISSUANCE', | ||
createdAt: '2024-01-09T13:09:29.020Z', | ||
id: '659d4589abb2c024ff2ef8e5', | ||
updatedAt: '2024-01-09T13:09:29.020Z', | ||
metadata: { | ||
creator: '', | ||
dataModel: '', | ||
issuer: '', | ||
dataModels: [''], | ||
organization: '', | ||
owner: '', | ||
pda: '', | ||
proof: '', | ||
requestTemplate: '', | ||
signedBy: '', | ||
status: '', | ||
}, | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.