'use strict' import nock from 'nock' import { EventName, EventCategory, EventComponent, EventInput } from '../../src/dto/shared.dto' import { expect } from 'chai' import { metrics } from '../../src/metrics' const apiKeyHash = 'dummyHash' const metricsUrl = 'https://affinity-metrics.dev.affinity-project.org' describe('Metrics', () => { const params: EventInput = { link: 'some_hash_from_did', name: EventName.DID_CREATED, category: EventCategory.DID, subCategory: 'registry', component: EventComponent.AffinidiBrowserSDK } it('#send', async() => { nock(metricsUrl) .post('/api/v1/events/createEvent') .reply(200, { name: 'Mocked Event' }) const response = await metrics.send(params, apiKeyHash, metricsUrl) expect(response).to.exist expect(response.name).to.be.equal('Mocked Event') }) it('#send handle and return an error', async() => { nock(metricsUrl) .post('/api/v1/events/createEvent') .reply(503, { name: 'Mocked Event' }) const result = await metrics.send(params, apiKeyHash, metricsUrl) expect(result.error).to.exist }) })