-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add contributable domains endpoint
- Loading branch information
Melisa Anabella Rossi
committed
May 13, 2024
1 parent
b656750
commit a0b7dc7
Showing
6 changed files
with
146 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DecentralandSignatureContext } from '@dcl/platform-crypto-middleware' | ||
import { HandlerContextWithPath } from '../../types' | ||
import { IHttpServerComponent } from '@well-known-components/interfaces' | ||
|
||
export async function getContributableDomainsHandler( | ||
ctx: HandlerContextWithPath<'worldsManager', '/world/contribute'> & DecentralandSignatureContext<any> | ||
): Promise<IHttpServerComponent.IResponse> { | ||
const { worldsManager } = ctx.components | ||
const address = ctx.verification!.auth | ||
const body = await worldsManager.getContributableDomains(address) | ||
return { | ||
status: 200, | ||
body | ||
} | ||
} |
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,95 @@ | ||
import { Authenticator } from '@dcl/crypto' | ||
import { test } from '../components' | ||
import { IWorldCreator, IWorldsManager, Permissions, PermissionType } from '../../src/types' | ||
import { defaultPermissions } from '../../src/logic/permissions-checker' | ||
import { Identity, getIdentity, getAuthHeaders } from '../utils' | ||
|
||
test('ContributorHandler', function ({ components }) { | ||
let worldCreator: IWorldCreator | ||
let worldsManager: IWorldsManager | ||
let identity: Identity | ||
let worldName: string | ||
|
||
function makeRequest(path: string, identity: Identity) { | ||
return components.localFetch.fetch(path, { | ||
method: 'GET', | ||
headers: { | ||
...getAuthHeaders( | ||
'get', | ||
path, | ||
{ | ||
origin: 'https://play.decentraland.org', | ||
intent: 'dcl:explorer:comms-handshake', | ||
signer: 'dcl:explorer', | ||
isGuest: 'false' | ||
}, | ||
(payload) => | ||
Authenticator.signPayload( | ||
{ | ||
ephemeralIdentity: identity.ephemeralIdentity, | ||
expiration: new Date(), | ||
authChain: identity.authChain.authChain | ||
}, | ||
payload | ||
) | ||
) | ||
} | ||
}) | ||
} | ||
|
||
beforeEach(async () => { | ||
worldCreator = components.worldCreator | ||
worldsManager = components.worldsManager | ||
|
||
identity = await getIdentity() | ||
|
||
const created = await worldCreator.createWorldWithScene() | ||
worldName = created.worldName | ||
}) | ||
|
||
describe('/world/contribute', () => { | ||
describe("when user doesn't have contributor permission to any world", () => { | ||
it('returns an empty list', async () => { | ||
const r = await makeRequest('/world/contribute', identity) | ||
|
||
expect(r.status).toBe(200) | ||
expect(await r.json()).toMatchObject({ domains: [], count: 0 }) | ||
}) | ||
}) | ||
|
||
describe('when user has streamer permission to world', () => { | ||
it('returns list of domains', async () => { | ||
const permissions: Permissions = { | ||
...defaultPermissions(), | ||
streaming: { | ||
type: PermissionType.AllowList, | ||
wallets: [identity.realAccount.address.toLowerCase()] | ||
} | ||
} | ||
await worldsManager.storePermissions(worldName, permissions) | ||
const r = await makeRequest('/world/contribute', identity) | ||
|
||
expect(r.status).toBe(200) | ||
expect(await r.json()).toMatchObject({ domains: [worldName], count: 1 }) | ||
}) | ||
}) | ||
|
||
describe('when user has deployment permission to world', () => { | ||
it('returns list of domains', async () => { | ||
const permissions: Permissions = { | ||
...defaultPermissions(), | ||
deployment: { | ||
type: PermissionType.AllowList, | ||
wallets: [identity.realAccount.address.toLocaleLowerCase()] | ||
} | ||
} | ||
|
||
await worldsManager.storePermissions(worldName, permissions) | ||
const r = await makeRequest('/world/contribute', identity) | ||
|
||
expect(r.status).toBe(200) | ||
expect(await r.json()).toMatchObject({ domains: [worldName], count: 1 }) | ||
}) | ||
}) | ||
}) | ||
}) |
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