File tree Expand file tree Collapse file tree 4 files changed +40
-3
lines changed Expand file tree Collapse file tree 4 files changed +40
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { account } from './actions/account'
2
+ import { ApiKey } from './entities/Apikey'
3
+
4
+ export class Client {
5
+ private apiKey : ApiKey
6
+ constructor ( apiKey : string ) {
7
+ this . apiKey = new ApiKey ( apiKey )
8
+ this . apiKey . validate ( )
9
+ }
10
+ account ( action : string ) : void {
11
+ if ( ! account . get ( action ) ) {
12
+ throw new Error ( 'unknown action' )
13
+ }
14
+ }
15
+ }
Original file line number Diff line number Diff line change @@ -6,13 +6,13 @@ import { EntityBase } from './EntityBase'
6
6
export class ApiKey extends EntityBase implements IEntity {
7
7
errorMessage : string = 'invalid'
8
8
private apiKey : string
9
- private keyLength : number = 33
9
+ private keyLength : number = 34
10
10
constructor ( apiKey : string ) {
11
11
super ( )
12
12
this . apiKey = apiKey
13
13
}
14
14
15
15
valid ( ) : boolean {
16
- return this . apiKey . length ! == this . keyLength
16
+ return this . apiKey . length = == this . keyLength
17
17
}
18
18
}
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import { Client } from '../src/Client'
3
+
4
+ test ( 'constructor is a function' , t => {
5
+ t . is ( typeof Client , 'function' )
6
+ } )
7
+
8
+ test ( 'client can be instantiated' , t => {
9
+ t . notThrows ( ( ) => new Client ( 'TRU5Z5MNWIEYP4F6DPH2T53IJWZIZ5GT1W' ) )
10
+ } ) ;
11
+
12
+ test ( 'invalid api key throws' , t => {
13
+ t . throws ( ( ) => new Client ( 'y' ) )
14
+ } ) ;
Original file line number Diff line number Diff line change @@ -8,9 +8,17 @@ test('Instantiated', (t)=> {
8
8
t . truthy ( a )
9
9
} )
10
10
11
- test ( 'is valid' , ( t ) => {
11
+ test ( 'key TRU5Z5MNWIEYP4F6DPH2T53IJWZIZ5GT1W is valid' , ( t ) => {
12
12
const apiKey = 'TRU5Z5MNWIEYP4F6DPH2T53IJWZIZ5GT1W'
13
13
const a = new ApiKey ( apiKey )
14
14
t . truthy ( a . valid ( ) )
15
15
} )
16
16
17
+ test ( 'foo is valid' , ( t ) => {
18
+ const apiKey = 'foo'
19
+ const a = new ApiKey ( apiKey )
20
+ t . false ( a . valid ( ) )
21
+ } )
22
+
23
+
24
+
You can’t perform that action at this time.
0 commit comments