@@ -6,80 +6,82 @@ describe('Letterbox', function () {
6
6
let letterbox ;
7
7
beforeEach ( function ( ) {
8
8
letterbox = new Letterbox ( ) ;
9
- spyOn ( letterbox , 'track' ) ;
9
+ letterbox . tracker = { accept : function ( ) { } } ;
10
+ spyOn ( letterbox , 'setup' ) ;
11
+ spyOn ( letterbox . tracker , 'accept' ) ;
10
12
} ) ;
11
13
it ( 'should accept a message without an envelope' , function ( ) {
12
- expect ( function ( ) { letterbox . write ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
14
+ expect ( function ( ) { letterbox . accept ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
13
15
expect ( letterbox . depth . maximum ) . toEqual ( 0 ) ;
14
16
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
15
17
expect ( function ( ) { letterbox . next ( ) ; } ) . not . toThrow ( ) ;
16
18
expect ( letterbox . depth . current ) . toEqual ( 0 ) ;
17
19
} ) ;
18
20
it ( 'cannot nest interchanges' , function ( ) {
19
- expect ( function ( ) { letterbox . write ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
21
+ expect ( function ( ) { letterbox . accept ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
20
22
expect ( letterbox . depth . minimum ) . toEqual ( 1 ) ;
21
23
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
22
- expect ( function ( ) { letterbox . write ( { name : 'UNB' } ) ; } ) . toThrow ( ) ;
24
+ expect ( function ( ) { letterbox . accept ( { name : 'UNB' } ) ; } ) . toThrow ( ) ;
23
25
} ) ;
24
26
it ( 'cannot open an interchange after a single message' , function ( ) {
25
- expect ( function ( ) { letterbox . write ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
27
+ expect ( function ( ) { letterbox . accept ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
26
28
expect ( letterbox . depth . maximum ) . toEqual ( 0 ) ;
27
29
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
28
30
expect ( function ( ) { letterbox . next ( ) ; } ) . not . toThrow ( ) ;
29
31
expect ( letterbox . depth . current ) . toEqual ( 0 ) ;
30
- expect ( function ( ) { letterbox . write ( { name : 'UNB' } ) ; } ) . toThrow ( ) ;
32
+ expect ( function ( ) { letterbox . accept ( { name : 'UNB' } ) ; } ) . toThrow ( ) ;
31
33
} ) ;
32
34
it ( 'cannot open a group without an interchange' , function ( ) {
33
- expect ( function ( ) { letterbox . write ( { name : 'UNG' } ) ; } ) . toThrow ( ) ;
35
+ expect ( function ( ) { letterbox . accept ( { name : 'UNG' } ) ; } ) . toThrow ( ) ;
34
36
} ) ;
35
37
for ( var name of [ 'UNB' , 'UNZ' , 'UNG' , 'UNE' ] ) {
36
38
it ( 'should not validate a ' + name + ' segment while tracking a message' , function ( ) {
37
39
// While no valid message contains an enveloping segment in it's segment
38
40
// table, this test is the equivalence of allowing such a messsage
39
41
// definition. Prohibiting enveloping segments in messages should be
40
42
// done by providing a correct segment table, not by algorithm design.
41
- expect ( function ( ) { letterbox . write ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
43
+ expect ( function ( ) { letterbox . accept ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
42
44
expect ( letterbox . depth . maximum ) . toEqual ( 0 ) ;
43
45
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
44
- expect ( function ( ) { letterbox . write ( { name : name } ) ; } ) . not . toThrow ( ) ;
45
- expect ( letterbox . track ) . toHaveBeenCalled ( ) ;
46
+ expect ( function ( ) { letterbox . accept ( { name : name } ) ; } ) . not . toThrow ( ) ;
47
+ expect ( letterbox . tracker . accept ) . toHaveBeenCalled ( ) ;
46
48
} ) ;
47
49
}
48
50
it ( 'should accept a message in an interchange' , function ( ) {
49
- expect ( function ( ) { letterbox . write ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
51
+ expect ( function ( ) { letterbox . accept ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
50
52
expect ( letterbox . depth . minimum ) . toEqual ( 1 ) ;
51
53
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
52
- expect ( function ( ) { letterbox . write ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
54
+ expect ( function ( ) { letterbox . accept ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
53
55
expect ( letterbox . depth . maximum ) . toEqual ( 1 ) ;
54
56
expect ( letterbox . depth . current ) . toEqual ( 2 ) ;
55
57
expect ( function ( ) { letterbox . next ( ) ; } ) . not . toThrow ( ) ;
56
58
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
57
- expect ( function ( ) { letterbox . write ( { name : 'UNZ' } ) ; } ) . not . toThrow ( ) ;
59
+ expect ( function ( ) { letterbox . accept ( { name : 'UNZ' } ) ; } ) . not . toThrow ( ) ;
58
60
expect ( letterbox . depth . current ) . toEqual ( 0 ) ;
59
61
} ) ;
60
62
it ( 'should not accept a group after a message' , function ( ) {
61
- expect ( function ( ) { letterbox . write ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
63
+ expect ( function ( ) { letterbox . accept ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
62
64
expect ( letterbox . depth . minimum ) . toEqual ( 1 ) ;
63
65
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
64
- expect ( function ( ) { letterbox . write ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
66
+ expect ( function ( ) { letterbox . accept ( { name : 'UNH' } ) ; } ) . not . toThrow ( ) ;
65
67
expect ( letterbox . depth . maximum ) . toEqual ( 1 ) ;
66
68
expect ( letterbox . depth . current ) . toEqual ( 2 ) ;
67
69
expect ( function ( ) { letterbox . next ( ) ; } ) . not . toThrow ( ) ;
68
70
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
69
- expect ( function ( ) { letterbox . write ( { name : 'UNG' } ) ; } ) . toThrow ( ) ;
71
+ expect ( function ( ) { letterbox . accept ( { name : 'UNG' } ) ; } ) . toThrow ( ) ;
70
72
} ) ;
71
73
it ( 'should not accept a group without an interchange' , function ( ) {
72
- expect ( function ( ) { letterbox . write ( { name : 'UNG' } ) ; } ) . toThrow ( ) ;
74
+ expect ( function ( ) { letterbox . accept ( { name : 'UNG' } ) ; } ) . toThrow ( ) ;
73
75
} ) ;
74
76
it ( 'should not accept a message after a group' , function ( ) {
75
- expect ( function ( ) { letterbox . write ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
77
+ expect ( function ( ) { letterbox . accept ( { name : 'UNB' } ) ; } ) . not . toThrow ( ) ;
76
78
expect ( letterbox . depth . minimum ) . toEqual ( 1 ) ;
77
79
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
78
- expect ( function ( ) { letterbox . write ( { name : 'UNG' } ) ; } ) . not . toThrow ( ) ;
80
+ expect ( function ( ) { letterbox . accept ( { name : 'UNG' } ) ; } ) . not . toThrow ( ) ;
79
81
expect ( letterbox . depth . minimum ) . toEqual ( 2 ) ;
80
82
expect ( letterbox . depth . current ) . toEqual ( 2 ) ;
81
- expect ( function ( ) { letterbox . write ( { name : 'UNE' } ) ; } ) . not . toThrow ( ) ;
83
+ expect ( function ( ) { letterbox . accept ( { name : 'UNE' } ) ; } ) . not . toThrow ( ) ;
82
84
expect ( letterbox . depth . current ) . toEqual ( 1 ) ;
83
- expect ( function ( ) { letterbox . write ( { name : 'UNH' } ) ; } ) . toThrow ( ) ;
85
+ expect ( function ( ) { letterbox . accept ( { name : 'UNH' } ) ; } ) . toThrow ( ) ;
84
86
} ) ;
85
87
} ) ;
0 commit comments