Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Goldman committed Jan 22, 2024
1 parent 56f4249 commit 7a9e056
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
3 changes: 1 addition & 2 deletions test/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { createWorldsManagerComponent } from '../src/adapters/worlds-manager'
import { createPermissionsManagerComponent } from '../src/adapters/permissions-manager'
import { createMockNameOwnership } from './mocks/name-ownership-mock'
import { createMockUpdateOwnerJob } from './mocks/update-owner-job-mock'
import { createSnsClientMock } from './mocks/sns-clientmock'
import { createSnsClientMock } from './mocks/sns-client-mock'
import { createDotEnvConfigComponent } from '@well-known-components/env-config-provider'
import { SnsClient } from '../src/adapters/sns-client'

Expand All @@ -48,7 +48,6 @@ async function initComponents(): Promise<TestComponents> {
const config = await createDotEnvConfigComponent(
{ path: ['.env.default', '.env'] },
{
AUTH_SECRET: 'some-secret',
SNS_ARN: 'some-arn'
}
)
Expand Down
64 changes: 46 additions & 18 deletions test/integration/reprocess-ab-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,61 @@
import { test } from '../components'
import { stringToUtf8Bytes } from 'eth-connect'
import { Authenticator } from '@dcl/crypto'
import { DeploymentToSqs } from '@dcl/schemas/dist/misc/deployments-to-sqs'

test('reprocess asset-bundles handler /reprocess-ab', function ({ components, stubComponents }) {
beforeEach(async () => {
const { config } = stubComponents
config.getString.withArgs('SNS_ARN').resolves('some-arn')
})

it('when world exists it responds', async () => {
it('can reprocess all worlds', async () => {
const { localFetch, worldCreator } = components
const { snsClient } = stubComponents

const files = new Map<string, Uint8Array>()
files.set('abc.png', Buffer.from(stringToUtf8Bytes('Hello world')))
const { entityId, owner } = await worldCreator.createWorldWithScene({})
const authChain = Authenticator.signPayload(owner, entityId)

const { entityId, worldName, entity } = await worldCreator.createWorldWithScene({})
snsClient.publishBatch.resolves({
Successful: [{ Id: 'mocked-id', MessageId: 'mocked-message-id', SequenceNumber: '1' }],
Failed: [],
$metadata: {}
})

const r = await localFetch
.fetch(`/reprocess-ab`, {
method: 'POST',
headers: {
Authorization: 'Bearer setup_some_secret_here'
const r = await localFetch.fetch(`/reprocess-ab`, {
method: 'POST',
headers: {
Authorization: 'Bearer setup_some_secret_here'
}
})

const baseUrl = `http://0.0.0.0:3000`
expect(r.status).toEqual(200)
expect(await r.json()).toMatchObject({
baseUrl: baseUrl,
batch: expect.arrayContaining<DeploymentToSqs>([
{
entity: {
entityId,
authChain
},
contentServerUrls: [baseUrl]
}
})
.catch(console.error)

// console.log(r.status, r.statusText)
// expect(r.status).toEqual(200)
// expect(await r.json()).toEqual({
// name: worldName
// })
]),
successful: 1,
failed: 0
})
})

it('can not be called if no SNS_ARN configured', async () => {
const { localFetch } = components

const r = await localFetch.fetch(`/reprocess-ab`, {
method: 'POST',
headers: {
Authorization: 'Bearer setup_some_secret_here'
}
})
expect(r.status).toEqual(500)
expect(await r.json()).toMatchObject({ error: 'Internal Server Error' })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ export function createSnsClientMock(): SnsClient {

const publishBatch = jest.fn()
publishBatch.mockImplementation(() => ({
promise: jest.fn().mockResolvedValue({
Successful: ['mocked-message-id'],
Failed: []
})
Successful: [{ Id: 'mocked-id', MessageId: 'mocked-message-id', SequenceNumber: '1' }],
Failed: [],
$metadata: {}
}))

return {
Expand Down

0 comments on commit 7a9e056

Please sign in to comment.