-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e27489e
commit fbd9135
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Credentials } from '../Credentials'; | ||
|
||
describe('auth/Credentials', () => { | ||
it('should require a username and an API key', () => { | ||
const creds = new Credentials('aUserName', 'anApiKey'); | ||
|
||
expect(creds.username).toBe('aUserName'); | ||
expect(creds.apiKey).toBe('anApiKey'); | ||
}); | ||
|
||
it('should fail if api key or username are not present', () => { | ||
expect(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const creds = new Credentials('aUserName', undefined as any); | ||
expect(creds.username).toBe('aUserName'); | ||
}).toThrow(); | ||
|
||
expect(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const creds = new Credentials(undefined as any, 'anApiKey'); | ||
expect(creds.username).toBe(undefined); | ||
}).toThrow(); | ||
}); | ||
|
||
it('has a default server', () => { | ||
const creds = new Credentials('aUser', 'anApiKey'); | ||
expect(creds.serverURL).toBe('https://aUser.carto.com/'); | ||
}); | ||
|
||
it('can manage different servers', () => { | ||
const customServer = 'http://127.0.0.1:8181/user/{user}'; | ||
const creds = new Credentials('aUser', 'anApiKey', customServer); | ||
expect(creds.serverURL).toBe('http://127.0.0.1:8181/user/aUser/'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import MetricsEvent from '../MetricsEvent'; | ||
|
||
describe('core/MetricsEvent', () => { | ||
it('can be created easily', () => { | ||
const event = new MetricsEvent('mytestlib', 'name of this test'); | ||
|
||
expect(event.source).toBe('mytestlib'); | ||
expect(event.name).toBe('name of this test'); | ||
expect(event.groupId).toBeTruthy(); | ||
}); | ||
|
||
it('can be created with a custom id', () => { | ||
const event = new MetricsEvent('mytestlib', 'name of this test', 'id'); | ||
|
||
expect(event.source).toBe('mytestlib'); | ||
expect(event.name).toBe('name of this test'); | ||
expect(event.groupId).toBe('id'); | ||
}); | ||
|
||
it('can generate proper headers', () => { | ||
const event = new MetricsEvent('mytestlib', 'name of this test', 'id'); | ||
|
||
const headers = event.getHeaders(); | ||
expect(headers).toBeTruthy(); | ||
expect(headers[0]).toEqual(['Carto-Event-Source', 'mytestlib']); | ||
expect(headers[1]).toEqual(['Carto-Event', 'name of this test']); | ||
expect(headers[2]).toEqual(['Carto-Event-Group-Id', 'id']); | ||
}); | ||
}); |