Skip to content

Commit

Permalink
Merge pull request #634 from nevermined-io/feat/update-profile-methods
Browse files Browse the repository at this point in the history
feat: prepare methods to new profile restrictions
  • Loading branch information
eruizgar91 authored Mar 1, 2024
2 parents 0ed6985 + 125fa09 commit 98794b4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion integration/nevermined/Permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Permissions', () => {
userId: userProfile.userId,
type: [PermissionType.Read, PermissionType.Update, PermissionType.Delete],
issuer: account2.getId(),
holder: userProfile.addresses[0],
holder: account1.getId(),
}
})

Expand Down
4 changes: 1 addition & 3 deletions integration/nevermined/Profiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ describe('User Profiles', () => {
const response = await nevermined.services.profiles.findOneByAddress(account3.getId())

assert.deepEqual(response, {
...newProfile,
userId: response.userId,
creationDate: response.creationDate,
updateDate: response.updateDate,
name: response.name,
})
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "2.2.3",
"version": "2.2.4",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
10 changes: 6 additions & 4 deletions src/services/metadata/Profiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MarketplaceApi } from './MarketplaceAPI'
import { NewProfile, Profile } from './types'
import { NewProfile, Profile, ReducedProfile } from './types'
import { HttpError, ApiError } from '../../errors'

const profilePath = '/api/v1/metadata/profiles'
Expand Down Expand Up @@ -56,7 +56,9 @@ export class Profiles extends MarketplaceApi {
const fullUrl = `${this.url}${profilePath}/${userId}`

try {
const response = await this.nevermined.utils.fetch.get(fullUrl)
const response = await this.nevermined.utils.fetch.get(fullUrl, {
Authorization: `Bearer ${this.config.marketplaceAuthToken}`,
})

if (response.ok) {
return response.json() as Promise<Profile>
Expand All @@ -71,14 +73,14 @@ export class Profiles extends MarketplaceApi {
}
}

public async findOneByAddress(address: string): Promise<Profile> {
public async findOneByAddress(address: string): Promise<ReducedProfile> {
const fullUrl = `${this.url}${profilePath}/address/${address}`

try {
const response = await this.nevermined.utils.fetch.get(fullUrl)

if (response.ok) {
return response.json() as Promise<Profile>
return response.json() as Promise<ReducedProfile>
}

throw new HttpError(
Expand Down
5 changes: 5 additions & 0 deletions src/services/metadata/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ export interface Profile extends NewProfile {
creationDate: Date
updateDate: Date
}

export interface ReducedProfile {
userId: string
name?: string
}
4 changes: 2 additions & 2 deletions test/profiles/Profiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ describe('Profiles', () => {

it('should get a profile by address', async () => {
spy.on(nevermined.utils.fetch, 'get', () => {
return reponsify(profile)
return reponsify({ userId: profile.userId, name: profile.name })
})

const result = await profiles.findOneByAddress(profile.addresses[0])

assert.equal(result, profile)
assert.deepEqual(result, { userId: profile.userId, name: profile.name })
})

it('should update a profile by userId', async () => {
Expand Down

0 comments on commit 98794b4

Please sign in to comment.