From 7a9e05670bce2412b5d7215aa95f892b5de12a3d Mon Sep 17 00:00:00 2001 From: Mariano Goldman Date: Mon, 22 Jan 2024 17:51:00 -0300 Subject: [PATCH] tests --- test/components.ts | 3 +- test/integration/reprocess-ab-handler.spec.ts | 64 +++++++++++++------ .../{sns-clientmock.ts => sns-client-mock.ts} | 7 +- 3 files changed, 50 insertions(+), 24 deletions(-) rename test/mocks/{sns-clientmock.ts => sns-client-mock.ts} (76%) diff --git a/test/components.ts b/test/components.ts index e1d24541..177d7228 100644 --- a/test/components.ts +++ b/test/components.ts @@ -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' @@ -48,7 +48,6 @@ async function initComponents(): Promise { const config = await createDotEnvConfigComponent( { path: ['.env.default', '.env'] }, { - AUTH_SECRET: 'some-secret', SNS_ARN: 'some-arn' } ) diff --git a/test/integration/reprocess-ab-handler.spec.ts b/test/integration/reprocess-ab-handler.spec.ts index e5455a40..491de2a8 100644 --- a/test/integration/reprocess-ab-handler.spec.ts +++ b/test/integration/reprocess-ab-handler.spec.ts @@ -1,5 +1,6 @@ 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 () => { @@ -7,27 +8,54 @@ test('reprocess asset-bundles handler /reprocess-ab', function ({ components, st 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() - 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([ + { + 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' }) }) }) diff --git a/test/mocks/sns-clientmock.ts b/test/mocks/sns-client-mock.ts similarity index 76% rename from test/mocks/sns-clientmock.ts rename to test/mocks/sns-client-mock.ts index dfa7755f..2389ded6 100644 --- a/test/mocks/sns-clientmock.ts +++ b/test/mocks/sns-client-mock.ts @@ -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 {