|
1 | 1 | import { realHandler } from '../../lib/commands/context';
|
2 |
| -import { Configuration, Settings, Context } from '../../lib/settings'; |
| 2 | +import { Configuration } from '../../lib/settings'; |
3 | 3 |
|
4 |
| -describe('context --list', () => { |
5 |
| - test('runs', async() => { |
6 |
| - // GIVEN |
7 |
| - const configuration = new Configuration(); |
8 |
| - configuration.context.set('foo', 'bar'); |
| 4 | +test('context list', async() => { |
| 5 | + // GIVEN |
| 6 | + const configuration = new Configuration(); |
| 7 | + configuration.context.set('foo', 'bar'); |
9 | 8 |
|
10 |
| - expect(configuration.context.all).toEqual({ |
11 |
| - foo: 'bar', |
12 |
| - }); |
13 |
| - |
14 |
| - // WHEN |
15 |
| - await realHandler({ |
16 |
| - configuration, |
17 |
| - args: {}, |
18 |
| - } as any); |
19 |
| - }); |
20 |
| -}); |
21 |
| - |
22 |
| -describe('context --reset', () => { |
23 |
| - test('can remove a context key', async () => { |
24 |
| - // GIVEN |
25 |
| - const configuration = new Configuration(); |
26 |
| - configuration.context.set('foo', 'bar'); |
27 |
| - configuration.context.set('baz', 'quux'); |
28 |
| - |
29 |
| - expect(configuration.context.all).toEqual({ |
30 |
| - foo: 'bar', |
31 |
| - baz: 'quux', |
32 |
| - }); |
33 |
| - |
34 |
| - // WHEN |
35 |
| - await realHandler({ |
36 |
| - configuration, |
37 |
| - args: { reset: 'foo' }, |
38 |
| - } as any); |
39 |
| - |
40 |
| - // THEN |
41 |
| - expect(configuration.context.all).toEqual({ |
42 |
| - baz: 'quux', |
43 |
| - }); |
44 |
| - }); |
45 |
| - |
46 |
| - test('can remove a context key using number', async () => { |
47 |
| - // GIVEN |
48 |
| - const configuration = new Configuration(); |
49 |
| - configuration.context.set('foo', 'bar'); |
50 |
| - configuration.context.set('baz', 'quux'); |
51 |
| - |
52 |
| - expect(configuration.context.all).toEqual({ |
53 |
| - foo: 'bar', |
54 |
| - baz: 'quux', |
55 |
| - }); |
56 |
| - |
57 |
| - // WHEN |
58 |
| - await realHandler({ |
59 |
| - configuration, |
60 |
| - args: { reset: '1' }, |
61 |
| - } as any); |
62 |
| - |
63 |
| - // THEN |
64 |
| - expect(configuration.context.all).toEqual({ |
65 |
| - foo: 'bar', |
66 |
| - }); |
67 |
| - }); |
68 |
| - |
69 |
| - |
70 |
| - test('can reset matched pattern', async () => { |
71 |
| - // GIVEN |
72 |
| - const configuration = new Configuration(); |
73 |
| - configuration.context.set('foo', 'bar'); |
74 |
| - configuration.context.set('match-a', 'baz'); |
75 |
| - configuration.context.set('match-b', 'qux'); |
76 |
| - |
77 |
| - expect(configuration.context.all).toEqual({ |
78 |
| - 'foo': 'bar', |
79 |
| - 'match-a': 'baz', |
80 |
| - 'match-b': 'qux', |
81 |
| - }); |
82 |
| - |
83 |
| - // WHEN |
84 |
| - await realHandler({ |
85 |
| - configuration, |
86 |
| - args: { reset: 'match-*' }, |
87 |
| - } as any); |
88 |
| - |
89 |
| - // THEN |
90 |
| - expect(configuration.context.all).toEqual({ |
91 |
| - foo: 'bar', |
92 |
| - }); |
| 9 | + expect(configuration.context.all).toEqual({ |
| 10 | + foo: 'bar', |
93 | 11 | });
|
94 | 12 |
|
| 13 | + // WHEN |
| 14 | + await realHandler({ |
| 15 | + configuration, |
| 16 | + args: {}, |
| 17 | + } as any); |
| 18 | +}); |
95 | 19 |
|
96 |
| - test('prefers an exact match', async () => { |
97 |
| - // GIVEN |
98 |
| - const configuration = new Configuration(); |
99 |
| - configuration.context.set('foo', 'bar'); |
100 |
| - configuration.context.set('fo*', 'baz'); |
101 |
| - |
102 |
| - expect(configuration.context.all).toEqual({ |
103 |
| - 'foo': 'bar', |
104 |
| - 'fo*': 'baz', |
105 |
| - }); |
106 |
| - |
107 |
| - // WHEN |
108 |
| - await realHandler({ |
109 |
| - configuration, |
110 |
| - args: { reset: 'fo*' }, |
111 |
| - } as any); |
112 |
| - |
113 |
| - // THEN |
114 |
| - expect(configuration.context.all).toEqual({ |
115 |
| - foo: 'bar', |
116 |
| - }); |
117 |
| - }); |
118 |
| - |
119 |
| - |
120 |
| - test('doesn\'t throw when at least one match is reset', async () => { |
121 |
| - // GIVEN |
122 |
| - const configuration = new Configuration(); |
123 |
| - const readOnlySettings = new Settings({ |
124 |
| - 'foo': 'bar', |
125 |
| - 'match-a': 'baz', |
126 |
| - }, true); |
127 |
| - configuration.context = new Context(readOnlySettings, new Settings()); |
128 |
| - configuration.context.set('match-b', 'quux'); |
129 |
| - |
130 |
| - // When |
131 |
| - await expect(realHandler({ |
132 |
| - configuration, |
133 |
| - args: { reset: 'match-*' }, |
134 |
| - } as any)); |
| 20 | +test('context reset can remove a context key', async () => { |
| 21 | + // GIVEN |
| 22 | + const configuration = new Configuration(); |
| 23 | + configuration.context.set('foo', 'bar'); |
| 24 | + configuration.context.set('baz', 'quux'); |
135 | 25 |
|
136 |
| - // Then |
137 |
| - expect(configuration.context.all).toEqual({ |
138 |
| - 'foo': 'bar', |
139 |
| - 'match-a': 'baz', |
140 |
| - }); |
| 26 | + expect(configuration.context.all).toEqual({ |
| 27 | + foo: 'bar', |
| 28 | + baz: 'quux', |
141 | 29 | });
|
142 | 30 |
|
143 |
| - test('throws when key not found', async () => { |
144 |
| - // GIVEN |
145 |
| - const configuration = new Configuration(); |
146 |
| - configuration.context.set('foo', 'bar'); |
147 |
| - |
148 |
| - expect(configuration.context.all).toEqual({ |
149 |
| - foo: 'bar', |
150 |
| - }); |
| 31 | + // WHEN |
| 32 | + await realHandler({ |
| 33 | + configuration, |
| 34 | + args: { reset: 'foo' }, |
| 35 | + } as any); |
151 | 36 |
|
152 |
| - // THEN |
153 |
| - await expect(realHandler({ |
154 |
| - configuration, |
155 |
| - args: { reset: 'baz' }, |
156 |
| - } as any)).rejects.toThrow(/No context value matching key/); |
| 37 | + // THEN |
| 38 | + expect(configuration.context.all).toEqual({ |
| 39 | + baz: 'quux', |
157 | 40 | });
|
| 41 | +}); |
158 | 42 |
|
| 43 | +test('context reset can remove a context key using number', async () => { |
| 44 | + // GIVEN |
| 45 | + const configuration = new Configuration(); |
| 46 | + configuration.context.set('foo', 'bar'); |
| 47 | + configuration.context.set('baz', 'quux'); |
159 | 48 |
|
160 |
| - test('throws when no key of index found', async () => { |
161 |
| - // GIVEN |
162 |
| - const configuration = new Configuration(); |
163 |
| - configuration.context.set('foo', 'bar'); |
164 |
| - |
165 |
| - expect(configuration.context.all).toEqual({ |
166 |
| - foo: 'bar', |
167 |
| - }); |
168 |
| - |
169 |
| - // THEN |
170 |
| - await expect(realHandler({ |
171 |
| - configuration, |
172 |
| - args: { reset: '2' }, |
173 |
| - } as any)).rejects.toThrow(/No context key with number/); |
174 |
| - }); |
175 |
| - |
176 |
| - |
177 |
| - test('throws when resetting read-only values', async () => { |
178 |
| - // GIVEN |
179 |
| - const configuration = new Configuration(); |
180 |
| - const readOnlySettings = new Settings({ |
181 |
| - foo: 'bar', |
182 |
| - }, true); |
183 |
| - configuration.context = new Context(readOnlySettings); |
184 |
| - |
185 |
| - expect(configuration.context.all).toEqual({ |
186 |
| - foo: 'bar', |
187 |
| - }); |
188 |
| - |
189 |
| - // THEN |
190 |
| - await expect(realHandler({ |
191 |
| - configuration, |
192 |
| - args: { reset: 'foo' }, |
193 |
| - } as any)).rejects.toThrow(/Cannot reset readonly context value with key/); |
| 49 | + expect(configuration.context.all).toEqual({ |
| 50 | + foo: 'bar', |
| 51 | + baz: 'quux', |
194 | 52 | });
|
195 | 53 |
|
| 54 | + // WHEN |
| 55 | + await realHandler({ |
| 56 | + configuration, |
| 57 | + args: { reset: '1' }, |
| 58 | + } as any); |
196 | 59 |
|
197 |
| - test('throws when no matches could be reset', async () => { |
198 |
| - // GIVEN |
199 |
| - const configuration = new Configuration(); |
200 |
| - const readOnlySettings = new Settings({ |
201 |
| - 'foo': 'bar', |
202 |
| - 'match-a': 'baz', |
203 |
| - 'match-b': 'quux', |
204 |
| - }, true); |
205 |
| - configuration.context = new Context(readOnlySettings); |
206 |
| - |
207 |
| - expect(configuration.context.all).toEqual({ |
208 |
| - 'foo': 'bar', |
209 |
| - 'match-a': 'baz', |
210 |
| - 'match-b': 'quux', |
211 |
| - }); |
212 |
| - |
213 |
| - // THEN |
214 |
| - await expect(realHandler({ |
215 |
| - configuration, |
216 |
| - args: { reset: 'match-*' }, |
217 |
| - } as any)).rejects.toThrow(/None of the matched context values could be reset/); |
| 60 | + // THEN |
| 61 | + expect(configuration.context.all).toEqual({ |
| 62 | + foo: 'bar', |
218 | 63 | });
|
219 |
| - |
220 | 64 | });
|
221 |
| - |
0 commit comments