-
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: added user related methods and test
- Loading branch information
1 parent
c06a800
commit 2d9ad57
Showing
5 changed files
with
350 additions
and
2 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
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 |
---|---|---|
@@ -1,7 +1,23 @@ | ||
import { FilterPDAInput } from '../.mesh'; | ||
|
||
export enum UserIdentifierType { | ||
EMAIL = 'EMAIL', | ||
EVM = 'EVM', | ||
GATEWAY_ID = 'GATEWAY_ID', | ||
SOLANA = 'SOLANA', | ||
USER_ID = 'USER_ID', | ||
} | ||
|
||
export enum PDAStatus { | ||
'Expired' = 'Expired', | ||
'Revoked' = 'Revoked', | ||
'Suspended' = 'Suspended', | ||
'Valid' = 'Valid', | ||
} | ||
|
||
export type PDAFilter = { | ||
filter?: FilterPDAInput; | ||
order?: JSON; | ||
skip: number; | ||
take: number; | ||
}; |
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,220 @@ | ||
import { | ||
FilterDataModelInput, | ||
FilterDataRequestTemplateInput, | ||
FilterPDAInput, | ||
Sdk, | ||
UpdateUserInput, | ||
} from '../../.mesh'; | ||
import { PDAFilter, UserIdentifierType } from '../types'; | ||
|
||
export class User { | ||
private 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) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* 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: UserIdentifierType; | ||
value: string; | ||
}) { | ||
try { | ||
return await this.sdk.user_query({ input: { type, value } }); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function `getAllUsers` is an asynchronous function that queries the users using an SDK and | ||
* returns the result, or throws an error if something goes wrong. | ||
* @returns the result of the `users_query()` method call. | ||
*/ | ||
async getAllUsers() { | ||
try { | ||
return await this.sdk.users_query(); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* 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?: FilterPDAInput) { | ||
try { | ||
return (await this.sdk.myPDACount_query({ filter })).myPDACount; | ||
} catch (error: any) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function `myPDAs` is an asynchronous function that takes in a `PDAFilter` object and returns a | ||
* promise that resolves to a `myPDAs_queryQuery` object. | ||
* @param {PDAFilter} - - `filter`: An object that contains filter criteria for the query. | ||
* @returns a Promise that resolves to a value of type `myPDAs_queryQuery`. | ||
*/ | ||
async myPDAs({ filter, order, skip, take }: PDAFilter) { | ||
try { | ||
return await this.sdk.myPDAs_query({ filter, order, skip, take }); | ||
} catch (error: any) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* 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) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function `myDataRequestTemplatesCount` is an asynchronous function that retrieves the count of | ||
* data request templates based on an optional filter and returns the count. | ||
* @param {FilterDataRequestTemplateInput} [filter] - The `filter` parameter is an optional input | ||
* that allows you to specify criteria for filtering the data request templates. It is of type | ||
* `FilterDataRequestTemplateInput`. You can use this parameter to narrow down the results based on | ||
* specific conditions such as template name, creator, or any other relevant attributes. | ||
* @returns the count of myDataRequestTemplates that match the provided filter. | ||
*/ | ||
async myDataRequestTemplatesCount(filter?: FilterDataRequestTemplateInput) { | ||
try { | ||
return (await this.sdk.myDataRequestTemplatesCount_query({ filter })) | ||
.myDataRequestTemplatesCount; | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function `updateUser` updates a user's information and returns the updated user. | ||
* @param {UpdateUserInput} updatedUser - The `updatedUser` parameter is an object of type | ||
* `UpdateUserInput`. It contains the data that will be used to update a user. The specific | ||
* properties and their types within the `UpdateUserInput` object will depend on the requirements of | ||
* your application. | ||
* @returns The updateUser function is returning the result of the updateUser_mutation API call. | ||
*/ | ||
async updateUser(updatedUser: UpdateUserInput) { | ||
try { | ||
return await this.sdk.updateUser_mutation({ input: updatedUser }); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function updates the display name of the user using a mutation and returns the result, or | ||
* throws an error if something goes wrong. | ||
* @param {string} displayName - The `displayName` parameter is a string that represents the new | ||
* display name that you want to update. | ||
* @returns the result of the `updateMyDisplayName_mutation` method call, which is likely a Promise | ||
* that resolves to the updated display name. | ||
*/ | ||
async updateMyDisplayName(displayName: string) { | ||
try { | ||
return await this.sdk.updateMyDisplayName_mutation({ displayName }); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function `updateMyGatewayId` updates the gateway ID using a mutation and returns the result, | ||
* or throws an error if something goes wrong. | ||
* @param {string} gatewayId - The `gatewayId` parameter is a string that represents the ID of a | ||
* gateway. | ||
* @returns the result of the `updateMyGatewayId_mutation` method call, which is awaited using the | ||
* `await` keyword. | ||
*/ | ||
async updateMyGatewayId(gatewayId: string) { | ||
try { | ||
return await this.sdk.updateMyGatewayId_mutation({ gatewayId }); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function updates the user's profile picture by making a mutation request to the SDK. | ||
* @param {string} profilePictureUrl - The `profilePictureUrl` parameter is a string that represents | ||
* the URL of the new profile picture that you want to update. | ||
* @returns the result of the `updateMyProfilePicture_mutation` mutation. | ||
*/ | ||
async updateMyProfilePicture(profilePictureUrl: string) { | ||
try { | ||
return await this.sdk.updateMyProfilePicture_mutation({ | ||
profilePictureUrl, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
|
||
/** | ||
* The function `updateNotificationEmail` updates the notification email by making a mutation request | ||
* to the SDK and returns the result, or throws an error if something goes wrong. | ||
* @param {string} email - The email parameter is a string that represents the new notification email | ||
* that needs to be updated. | ||
* @returns the result of the `updateNotificationEmail_mutation` method call. | ||
*/ | ||
async updateNotificationEmail(email: string) { | ||
try { | ||
return (await this.sdk.updateNotificationEmail_mutation({ email })) | ||
.updateNotificationEmail; | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Something went wrong'); | ||
} | ||
} | ||
} |
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,111 @@ | ||
import { Gateway } from '../src/Gateway'; | ||
|
||
const DEFAULT_TIMEOUT = 10000; | ||
|
||
let api: Gateway; | ||
|
||
beforeAll(() => { | ||
api = new Gateway({ | ||
apiKey: 'm9Y5ntNcTlwQ2LbRpYr6K_VhxJXuZJ6Q', | ||
token: | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm90b2NvbF9pZCI6IjkwNzcwODA2LWFlMGMtNGExNS05MjYzLWU5MWJhYWY1ZDkzZiIsImF1dGgiOnsiaWQiOiJlMjJiOWZkNi05NjgzLTRjZDgtOGZlOS1lZWU0YzFmYTJjZjciLCJ0eXBlIjoiV0FMTEVUIn0sImNyeXB0byI6eyJwdWJsaWNQZW0iOiItLS0tLUJFR0lOIFBVQkxJQyBLRVktLS0tLVxyXG5NSUlDSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQWc4QU1JSUNDZ0tDQWdFQXpUdTJCWVVSS3VvM2V2MGx0MjUzXHJcblR3SDlGQkhUbU90dlRXYlQraTExSEF5WW5vUGx4UWV3M0cySnAvanNnS0cxbDN4WHBtdEEwVjlkUGxaUHhVS3BcclxueXM2cWNBdkhmaThpdm15dmk1WVhRYnQ4aE1rY3hKb1RzanZ4V092dTF1bjljVlVSUGkzOTJZTjVwV2lBOEdncVxyXG5zMjlvaGYzOVJDVnM4MkxGQlNCVkI0ZHRhRmJ1cnNlY0M1WStqZVB3UG9tLzJMUlpkTTJ3bFc3ZzhYVmNROUV4XHJcblVxSWpxS296YnVjYmpiT0Q2YXZnRm9JR3VpOVIxdzYrbWFLQmRPK1gxRU5tVGZURHhLclZNRFJtSHFOK0syY1ZcclxuK3NlTWEzcDBjT0VlTklOWjc2V2lhTlhwMjErZ0VSU3hIRkRNOVBjeEZYWGxGeVBEWE1oVkNVNm1xTDNXRmtjNFxyXG5uOTI0bC8zR09Sa1QzZmd4K1FqN2krNS9sU0ZQS2Q1R1U3bFN4VnVBb1hwYWQxUlFCWUxBZGo1dnJacjB5aUprXHJcbi94cjMzbVp6Q0NuN0ZhcW1JeDdSbU4vRk1Sc1JqRGdBd2FUb3RzZ05JZFVGZVZrRURCYm1EWnJtL0k5diswY0hcclxuczA0UCtxaG01b3JEaXFscGZoZVN0M3hqVit5a3Z3d0JIOElSeGdIQ0krZk1ZMThBbDBCSHlkckZhdldWbEVhY1xyXG4yRTFpbDFSdXU0OGxCVXliU0R4Y3Z5RXR5TU94N0ErY0dQcy93MGg5aUtZZy9OVnEvTFdwWjEzYmVzcS9QanpWXHJcbjR5ZnZaTkpyT3VxMXpkc29MdlVaUTVuMHJ1c21PekMyNlhMb3BpVlpUSWk3U1k4QzAvNFNlaVVvaU8vaVBFbnhcclxuOW5nL0RUMEsvQXlLbTBZQ1oxU2pwZ1VDQXdFQUFRPT1cclxuLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tXHJcbiJ9LCJ0eXBlIjoiYXV0aF90b2tlbiIsImlhdCI6MTY5ODIxMTg0N30.zUxmPhnrQlIEZ5pMzHBMFkcqPvjsIfs0er9Dylw5olE', | ||
}); | ||
}); | ||
|
||
describe('USER Testing', () => { | ||
// it( | ||
// "me", | ||
// async () => { | ||
// const { me } = await api.user.me(); | ||
// expect(me.gatewayId).toEqual("sid"); | ||
// }, | ||
// DEFAULT_TIMEOUT | ||
// ); | ||
|
||
// it( | ||
// "single user", | ||
// async () => { | ||
// const { user } = await api.user.getSingleUser({ | ||
// type: UserIdentifierType.GATEWAY_ID, | ||
// value: "sid", | ||
// }); | ||
// expect(user?.gatewayId).toEqual("sid"); | ||
// }, | ||
// DEFAULT_TIMEOUT | ||
// ); | ||
|
||
// it("all users", async () => { | ||
// const { users } = await api.user.getAllUsers(); | ||
// expect(users.length).toEqual(10); | ||
// }); | ||
|
||
it( | ||
'my pdas count', | ||
async () => { | ||
const count = await api.user.myPDACount({}); | ||
expect(count).toBeGreaterThan(0); | ||
}, | ||
DEFAULT_TIMEOUT, | ||
); | ||
|
||
it( | ||
'my pdas', | ||
async () => { | ||
const { myPDAs } = await api.user.myPDAs({ | ||
skip: 0, | ||
take: 10, | ||
}); | ||
expect(myPDAs.length).toBeGreaterThan(0); | ||
}, | ||
DEFAULT_TIMEOUT, | ||
); | ||
|
||
it( | ||
'my data models count', | ||
async () => { | ||
const count = await api.user.myDataModelsCount(); | ||
expect(count).toBeGreaterThan(0); | ||
}, | ||
DEFAULT_TIMEOUT, | ||
); | ||
|
||
it( | ||
'my data requests template count', | ||
async () => { | ||
const count = await api.user.myDataRequestTemplatesCount(); | ||
expect(count).toEqual(0); | ||
}, | ||
DEFAULT_TIMEOUT, | ||
); | ||
|
||
// it("update user", async () => { | ||
// const { updateUser } = await api.user.updateUser({ | ||
// displayName: "siddharth9890", | ||
// }); | ||
// expect(updateUser.displayName).toEqual("siddharth9890"); | ||
// }); | ||
|
||
it('update display username', async () => { | ||
const { updateMyDisplayName } = await api.user.updateMyDisplayName('sid'); | ||
expect(updateMyDisplayName).toEqual('sid'); | ||
}); | ||
|
||
// it("update gateway id", async () => { | ||
// const { updateMyGatewayId } = await api.user.updateMyGatewayId( | ||
// "siddharth9890" | ||
// ); | ||
// expect(updateMyGatewayId.gatewayId).toEqual("siddharth9890"); | ||
// }); | ||
|
||
it('update profile picture', async () => { | ||
const { updateMyProfilePicture } = | ||
await api.user.updateMyProfilePicture('siddharth9890'); | ||
expect(updateMyProfilePicture).toEqual('siddharth9890'); | ||
}); | ||
|
||
// it("update notification email", async () => { | ||
// const { user } = await api.user.updateNotificationEmail("test@gmail.com"); | ||
// console.log(user); | ||
// expect(user.email).toEqual("test@gmail.com"); | ||
// }); | ||
}); |