Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 0369fa4

Browse files
committed
Fix other integration tests
1 parent 823b76c commit 0369fa4

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

examples/ingest-file.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import fs from 'fs';
2-
import Client, { CloudURL, datasets } from '@axiomhq/axiom-node';
2+
import Client, { datasets } from '@axiomhq/axiom-node';
33

4-
const deploymentURL = process.env.AXIOM_URL || CloudURL;
5-
const accessToken = process.env.AXIOM_TOKEN;
6-
const client = new Client(deploymentURL, accessToken);
4+
const client = new Client();
75

86
async function ingestFile() {
97
const stream = fs.createReadStream('logs.json');

lib/client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class Client {
1515
starred: starred.Service;
1616
teams: teams.Service;
1717
tokens: {
18-
ingest: tokens.IngestService;
18+
api: tokens.APIService;
1919
personal: tokens.PersonalService;
2020
};
2121
users: users.Service;
@@ -29,7 +29,7 @@ export default class Client {
2929
this.starred = new starred.Service(basePath, accessToken, orgID);
3030
this.teams = new teams.Service(basePath, accessToken, orgID);
3131
this.tokens = {
32-
ingest: new tokens.IngestService(basePath, accessToken, orgID),
32+
api: new tokens.APIService(basePath, accessToken, orgID),
3333
personal: new tokens.PersonalService(basePath, accessToken, orgID),
3434
};
3535
this.users = new users.Service(basePath, accessToken, orgID);

lib/tokens.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export namespace tokens {
66
id?: string;
77
name: string;
88
description?: string;
9-
scopes: Array<string>;
9+
scopes?: Array<string>; // Only for API tokens
10+
permissions?: Array<string>; // Only for API tokens
1011
}
1112

1213
export interface RawToken {
1314
token: string;
1415
scopes: Array<string>;
16+
permissions: Array<string>;
1517
}
1618

1719
class Service extends HTTPClient {
@@ -51,15 +53,10 @@ export namespace tokens {
5153
delete = (id: string): Promise<AxiosResponse> => this.client.delete<AxiosResponse>(this.localPath + '/' + id);
5254
}
5355

54-
export class IngestService extends Service {
56+
export class APIService extends Service {
5557
constructor(basePath?: string, accessToken?: string, orgID?: string) {
56-
super('/api/v1/tokens/ingest', basePath, accessToken, orgID);
58+
super('/api/v1/tokens/api', basePath, accessToken, orgID);
5759
}
58-
59-
validate = (): Promise<boolean> =>
60-
this.client.get(this.localPath + '/validate').then((response) => {
61-
return response.status === 204;
62-
});
6360
}
6461

6562
export class PersonalService extends Service {

tests/integration/tokens.test.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { expect } from 'chai';
22

33
import { tokens } from '../../lib/tokens';
44

5-
describe('IngestTokensService', () => {
6-
const client = new tokens.IngestService();
5+
describe('APITokensService', () => {
6+
const client = new tokens.APIService();
77

88
let token: tokens.Token;
99

1010
before(async () => {
1111
token = await client.create({
1212
name: 'Test Token',
13-
scopes: [],
13+
scopes: ['*'],
14+
permissions: ['CanIngest'],
1415
});
1516
});
1617

@@ -22,10 +23,13 @@ describe('IngestTokensService', () => {
2223
it('should update a token', async () => {
2324
const updatedToken = await client.update(token.id!, {
2425
name: 'Updated Test Token',
25-
scopes: [],
26+
scopes: ['*'],
27+
permissions: ['CanQuery'],
2628
});
2729

2830
expect(updatedToken.name).to.equal('Updated Test Token');
31+
expect(updatedToken.permissions).to.contain('CanQuery');
32+
expect(updatedToken.permissions).to.not.contain('CanIngest');
2933

3034
token = updatedToken;
3135
});
@@ -54,14 +58,6 @@ describe('IngestTokensService', () => {
5458
expect(tokens.length).to.be.greaterThan(0);
5559
});
5660
});
57-
58-
describe('validate', () => {
59-
it('should validate token', async () => {
60-
const valid = await client.validate();
61-
62-
expect(valid).to.be.true;
63-
});
64-
});
6561
});
6662

6763
describe('PersonalTokensService', () => {

tests/unit/client.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Client', () => {
1212
expect(client.notifiers).not.empty;
1313
expect(client.starred).not.empty;
1414
expect(client.teams).not.empty;
15-
expect(client.tokens.ingest).not.empty;
15+
expect(client.tokens.api).not.empty;
1616
expect(client.tokens.personal).not.empty;
1717
expect(client.users).not.empty;
1818
expect(client.version).not.empty;

0 commit comments

Comments
 (0)