From 9436de57395f3dc27aed4b630f6dcbc932857140 Mon Sep 17 00:00:00 2001 From: Islam Shehata Date: Mon, 10 Jun 2024 18:38:34 +0300 Subject: [PATCH] test(annotations): added integration test for annotations --- integration/src/annotations.spec.ts | 67 +++++++++++++++++++++++++++++ packages/js/src/annotations.ts | 2 +- packages/js/src/index.ts | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 integration/src/annotations.spec.ts diff --git a/integration/src/annotations.spec.ts b/integration/src/annotations.spec.ts new file mode 100644 index 00000000..f1c767e6 --- /dev/null +++ b/integration/src/annotations.spec.ts @@ -0,0 +1,67 @@ +import { describe, expect, it, beforeAll, afterAll } from 'vitest'; +import { datasets, annotations } from '@axiomhq/js'; + +const datasetSuffix = process.env.AXIOM_DATASET_SUFFIX || 'local'; + +describe('AnnotationsService', () => { + const datasetName = `test-axiom-js-datasets-${datasetSuffix}`; + const datasetsClient = new datasets.Service({ token: process.env.AXIOM_TOKEN || '', url: process.env.AXIOM_URL, orgId: process.env.AXIOM_ORG_ID }); + const client = new annotations.Service({ token: process.env.AXIOM_TOKEN || '', url: process.env.AXIOM_URL, orgId: process.env.AXIOM_ORG_ID }); + let id: string = ''; + + beforeAll(async () => { + await datasetsClient.create({ + name: datasetName, + description: 'This is a test dataset for datasets integration tests.', + }); + }); + + afterAll(async () => { + const resp = await datasetsClient.delete(datasetName); + expect(resp.status).toEqual(204); + }); + + describe('create', () => { + it('creates annotations successfully', async () => { + const result = await client.create({ + type: 'test-deployment', + datasets: [datasetName], + title: 'test1', + description: 'This is a test description', + url: 'some-url', + }); + + expect(result).not.toEqual(null); + expect(result.title).toEqual("test1"); + + // set id + id = result.id; + }); + }); + + describe('update', () => { + it('should update the annotation', async () => { + const dataset = await client.update(id, { + description: 'This is a soon to be filled test dataset', + }); + + expect(dataset.description).toEqual('This is a soon to be filled test dataset'); + }); + }); + + describe('get', () => { + it('should get the annotation', async () => { + const annotation = await client.get(id); + + expect(annotation.title).toEqual("test1"); + }); + }); + + describe('list', () => { + it('should list the annotations', async () => { + const annotations = await client.list(); + + expect(annotations.length).toBeGreaterThan(0); + }); + }); +}); diff --git a/packages/js/src/annotations.ts b/packages/js/src/annotations.ts index 1faf40ed..5d5a79a7 100644 --- a/packages/js/src/annotations.ts +++ b/packages/js/src/annotations.ts @@ -3,7 +3,7 @@ import HTTPClient from './httpClient.js'; export namespace annotations { export interface Annotation { - id: number; + id: string; type: string; datasets: string[]; title?: string; diff --git a/packages/js/src/index.ts b/packages/js/src/index.ts index e056b45a..4238f1ee 100644 --- a/packages/js/src/index.ts +++ b/packages/js/src/index.ts @@ -1,4 +1,5 @@ export { AxiomWithoutBatching, Axiom, ContentType, ContentEncoding, IngestOptions, IngestStatus, IngestFailure, QueryOptionsBase, QueryOptions, QueryLegacy, Aggregation, AggregationOp, Filter, FilterOp, Order, Projection, VirtualColumn, QueryLegacyResult, QueryResult, Timeseries, Interval, EntryGroup, EntryGroupAgg, Entry, Status, Message, Query } from './client.js'; export { ClientOptions } from './httpClient.js'; export { datasets } from './datasets.js'; +export { annotations } from './annotations.js'; export { users } from './users.js';