-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check instance name is valid (#42)
* fix: check instance name is valid * fix: test should not depend on env variable * fix: test that valid instance names can be used
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
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,45 @@ | ||
import { Context } from './context'; | ||
import { createInstance, isValidInstanceName } from './core'; | ||
import { InvalidName } from './errors'; | ||
import { createFetch } from './fetch'; | ||
|
||
jest.mock('./fetch'); | ||
|
||
describe('Core functionalities', () => { | ||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('validate instance name', () => { | ||
expect(isValidInstanceName('myinstance')).toEqual(true); | ||
expect(isValidInstanceName('my-instance')).toEqual(false); | ||
}); | ||
|
||
test('an instance with an invalid name cannot be created', async () => { | ||
await expect( | ||
createInstance( | ||
new Context({ personalAccessToken: 'dummy' }), | ||
'eyevinn-test-adserver', | ||
'my-token', | ||
{ | ||
name: 'my-instance' | ||
} | ||
) | ||
).rejects.toThrow(new InvalidName('my-instance')); | ||
expect(createFetch).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('an instance with an valid name can be created', async () => { | ||
await expect( | ||
createInstance( | ||
new Context({ personalAccessToken: 'dummy' }), | ||
'eyevinn-test-adserver', | ||
'my-token', | ||
{ | ||
name: 'myinstance' | ||
} | ||
) | ||
).rejects.not.toThrow(new InvalidName('myinstance')); | ||
expect(createFetch).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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