aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/stores/__tests__
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-01-23 17:12:47 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-08 21:43:17 +0100
commit044b2de8c7861504704468ba441d4a6a37eed8f7 (patch)
tree940d2b7946d07a0c69b5e3ad46c25c599cf2aca7 /packages/main/src/stores/__tests__
parentfeat: Add selected service field to SharedStore (diff)
downloadsophie-044b2de8c7861504704468ba441d4a6a37eed8f7.tar.gz
sophie-044b2de8c7861504704468ba441d4a6a37eed8f7.tar.zst
sophie-044b2de8c7861504704468ba441d4a6a37eed8f7.zip
refactor: Move runtime state into shared models
Now the runtime state lives inside the model (instead of being associated to the static settings via a map), which simplifies state management. Static settings are now located inside the runtime models, so we must create tests to make sure that the settings are being persisted correctly. The contents of the config file are now generated as a view of store (instead of a snapshot), which adds flexibility. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
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
21import { config, Config, ConfigFileIn } from '../Config'; 21import type { ProfileConfig } from '../Profile';
22import type { PartialProfileSnapshotIn } from '../Profile'; 22import type { ServiceConfig } from '../Service';
23import type { PartialServiceSnapshotIn } from '../Service'; 23import { Config, sharedStore, SharedStore } from '../SharedStore';
24 24
25const profileProps: PartialProfileSnapshotIn = { 25const profileProps: ProfileConfig = {
26 name: 'Test profile', 26 name: 'Test profile',
27}; 27};
28 28
29const serviceProps: PartialServiceSnapshotIn = { 29const serviceProps: ServiceConfig = {
30 name: 'Test service', 30 name: 'Test service',
31 url: 'https://example.com', 31 url: 'https://example.com',
32}; 32};
33 33
34let sut: Config; 34let sut: SharedStore;
35 35
36beforeEach(() => { 36beforeEach(() => {
37 sut = config.create(); 37 sut = sharedStore.create();
38}); 38});
39 39
40describe('preprocessConfigFile', () => { 40describe('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);