diff options
Diffstat (limited to 'packages/main/src/stores/__tests__')
-rw-r--r-- | packages/main/src/stores/__tests__/SharedStore.spec.ts (renamed from packages/main/src/stores/__tests__/Config.spec.ts) | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/packages/main/src/stores/__tests__/Config.spec.ts b/packages/main/src/stores/__tests__/SharedStore.spec.ts index 22ccbc7..3ea187c 100644 --- a/packages/main/src/stores/__tests__/Config.spec.ts +++ b/packages/main/src/stores/__tests__/SharedStore.spec.ts | |||
@@ -18,28 +18,28 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { config, Config, ConfigFileIn } from '../Config'; | 21 | import type { ProfileConfig } from '../Profile'; |
22 | import type { PartialProfileSnapshotIn } from '../Profile'; | 22 | import type { ServiceConfig } from '../Service'; |
23 | import type { PartialServiceSnapshotIn } from '../Service'; | 23 | import { Config, sharedStore, SharedStore } from '../SharedStore'; |
24 | 24 | ||
25 | const profileProps: PartialProfileSnapshotIn = { | 25 | const profileProps: ProfileConfig = { |
26 | name: 'Test profile', | 26 | name: 'Test profile', |
27 | }; | 27 | }; |
28 | 28 | ||
29 | const serviceProps: PartialServiceSnapshotIn = { | 29 | const serviceProps: ServiceConfig = { |
30 | name: 'Test service', | 30 | name: 'Test service', |
31 | url: 'https://example.com', | 31 | url: 'https://example.com', |
32 | }; | 32 | }; |
33 | 33 | ||
34 | let sut: Config; | 34 | let sut: SharedStore; |
35 | 35 | ||
36 | beforeEach(() => { | 36 | beforeEach(() => { |
37 | sut = config.create(); | 37 | sut = sharedStore.create(); |
38 | }); | 38 | }); |
39 | 39 | ||
40 | describe('preprocessConfigFile', () => { | 40 | describe('loadConfig', () => { |
41 | it('should load profiles with an ID', () => { | 41 | it('should load profiles with an ID', () => { |
42 | sut.loadFromConfigFile({ | 42 | sut.loadConfig({ |
43 | profiles: [ | 43 | profiles: [ |
44 | { | 44 | { |
45 | id: 'someId', | 45 | id: 'someId', |
@@ -51,14 +51,14 @@ describe('preprocessConfigFile', () => { | |||
51 | }); | 51 | }); |
52 | 52 | ||
53 | it('should generate an ID for profiles without and ID', () => { | 53 | it('should generate an ID for profiles without and ID', () => { |
54 | sut.loadFromConfigFile({ | 54 | sut.loadConfig({ |
55 | profiles: [profileProps], | 55 | profiles: [profileProps], |
56 | }); | 56 | }); |
57 | expect(sut.profiles[0].id).toBeDefined(); | 57 | expect(sut.profiles[0].id).toBeDefined(); |
58 | }); | 58 | }); |
59 | 59 | ||
60 | it('should load services with an ID and a profile', () => { | 60 | it('should load services with an ID and a profile', () => { |
61 | sut.loadFromConfigFile({ | 61 | sut.loadConfig({ |
62 | profiles: [ | 62 | profiles: [ |
63 | { | 63 | { |
64 | id: 'someProfileId', | 64 | id: 'someProfileId', |
@@ -74,12 +74,12 @@ describe('preprocessConfigFile', () => { | |||
74 | ], | 74 | ], |
75 | }); | 75 | }); |
76 | expect(sut.services[0].id).toBe('someServiceId'); | 76 | expect(sut.services[0].id).toBe('someServiceId'); |
77 | expect(sut.services[0].profile).toBe(sut.profiles[0]); | 77 | expect(sut.services[0].settings.profile).toBe(sut.profiles[0]); |
78 | }); | 78 | }); |
79 | 79 | ||
80 | it('should refuse to load a profile without a name', () => { | 80 | it('should refuse to load a profile without a name', () => { |
81 | expect(() => { | 81 | expect(() => { |
82 | sut.loadFromConfigFile({ | 82 | sut.loadConfig({ |
83 | profiles: [ | 83 | profiles: [ |
84 | { | 84 | { |
85 | id: 'someProfileId', | 85 | id: 'someProfileId', |
@@ -87,13 +87,13 @@ describe('preprocessConfigFile', () => { | |||
87 | name: undefined, | 87 | name: undefined, |
88 | }, | 88 | }, |
89 | ], | 89 | ], |
90 | } as unknown as ConfigFileIn); | 90 | } as unknown as Config); |
91 | }).toThrow(); | 91 | }).toThrow(); |
92 | expect(sut.profiles).toHaveLength(0); | 92 | expect(sut.profiles).toHaveLength(0); |
93 | }); | 93 | }); |
94 | 94 | ||
95 | it('should load services without an ID but with a profile', () => { | 95 | it('should load services without an ID but with a profile', () => { |
96 | sut.loadFromConfigFile({ | 96 | sut.loadConfig({ |
97 | profiles: [ | 97 | profiles: [ |
98 | { | 98 | { |
99 | id: 'someProfileId', | 99 | id: 'someProfileId', |
@@ -108,11 +108,11 @@ describe('preprocessConfigFile', () => { | |||
108 | ], | 108 | ], |
109 | }); | 109 | }); |
110 | expect(sut.services[0].id).toBeDefined(); | 110 | expect(sut.services[0].id).toBeDefined(); |
111 | expect(sut.services[0].profile).toBe(sut.profiles[0]); | 111 | expect(sut.services[0].settings.profile).toBe(sut.profiles[0]); |
112 | }); | 112 | }); |
113 | 113 | ||
114 | it('should create a profile for a service with an ID but no profile', () => { | 114 | it('should create a profile for a service with an ID but no profile', () => { |
115 | sut.loadFromConfigFile({ | 115 | sut.loadConfig({ |
116 | services: [ | 116 | services: [ |
117 | { | 117 | { |
118 | id: 'someServiceId', | 118 | id: 'someServiceId', |
@@ -121,12 +121,14 @@ describe('preprocessConfigFile', () => { | |||
121 | ], | 121 | ], |
122 | }); | 122 | }); |
123 | expect(sut.services[0].id).toBe('someServiceId'); | 123 | expect(sut.services[0].id).toBe('someServiceId'); |
124 | expect(sut.services[0].profile).toBeDefined(); | 124 | expect(sut.services[0].settings.profile).toBeDefined(); |
125 | expect(sut.services[0].profile.name).toBe(serviceProps.name); | 125 | expect(sut.services[0].settings.profile.settings.name).toBe( |
126 | serviceProps.name, | ||
127 | ); | ||
126 | }); | 128 | }); |
127 | 129 | ||
128 | it('should create a profile for a service without an ID or profile', () => { | 130 | it('should create a profile for a service without an ID or profile', () => { |
129 | sut.loadFromConfigFile({ | 131 | sut.loadConfig({ |
130 | services: [ | 132 | services: [ |
131 | { | 133 | { |
132 | ...serviceProps, | 134 | ...serviceProps, |
@@ -134,13 +136,15 @@ describe('preprocessConfigFile', () => { | |||
134 | ], | 136 | ], |
135 | }); | 137 | }); |
136 | expect(sut.services[0].id).toBeDefined(); | 138 | expect(sut.services[0].id).toBeDefined(); |
137 | expect(sut.services[0].profile).toBeDefined(); | 139 | expect(sut.services[0].settings.profile).toBeDefined(); |
138 | expect(sut.services[0].profile.name).toBe(serviceProps.name); | 140 | expect(sut.services[0].settings.profile.settings.name).toBe( |
141 | serviceProps.name, | ||
142 | ); | ||
139 | }); | 143 | }); |
140 | 144 | ||
141 | it('should refuse to load a service without a name', () => { | 145 | it('should refuse to load a service without a name', () => { |
142 | expect(() => { | 146 | expect(() => { |
143 | sut.loadFromConfigFile({ | 147 | sut.loadConfig({ |
144 | services: [ | 148 | services: [ |
145 | { | 149 | { |
146 | id: 'someServiceId', | 150 | id: 'someServiceId', |
@@ -148,7 +152,7 @@ describe('preprocessConfigFile', () => { | |||
148 | name: undefined, | 152 | name: undefined, |
149 | }, | 153 | }, |
150 | ], | 154 | ], |
151 | } as unknown as ConfigFileIn); | 155 | } as unknown as Config); |
152 | }).toThrow(); | 156 | }).toThrow(); |
153 | expect(sut.profiles).toHaveLength(0); | 157 | expect(sut.profiles).toHaveLength(0); |
154 | expect(sut.services).toHaveLength(0); | 158 | expect(sut.services).toHaveLength(0); |