caprover-api 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/ApiManager.js +10 -3
- package/package.json +1 -1
- package/src/api/ApiManager.ts +22 -9
- package/test/ApiManager.test.js +45 -0
package/dist/api/ApiManager.js
CHANGED
|
@@ -78,12 +78,19 @@ class ApiManager {
|
|
|
78
78
|
}
|
|
79
79
|
saveTheme(oldName, theme) {
|
|
80
80
|
const http = this.http;
|
|
81
|
-
|
|
82
|
-
.then(http.fetch(http.POST, '/user/system/themes/update', {
|
|
81
|
+
const payload = {
|
|
83
82
|
oldName,
|
|
84
83
|
name: theme.name,
|
|
85
84
|
content: theme.content,
|
|
86
|
-
}
|
|
85
|
+
};
|
|
86
|
+
if (theme.extra !== undefined) {
|
|
87
|
+
payload.extra = theme.extra;
|
|
88
|
+
}
|
|
89
|
+
if (theme.headEmbed !== undefined) {
|
|
90
|
+
payload.headEmbed = theme.headEmbed;
|
|
91
|
+
}
|
|
92
|
+
return Promise.resolve() //
|
|
93
|
+
.then(http.fetch(http.POST, '/user/system/themes/update', payload));
|
|
87
94
|
}
|
|
88
95
|
deleteTheme(themeName) {
|
|
89
96
|
const http = this.http;
|
package/package.json
CHANGED
package/src/api/ApiManager.ts
CHANGED
|
@@ -145,15 +145,28 @@ export default class ApiManager {
|
|
|
145
145
|
|
|
146
146
|
saveTheme(oldName: string, theme: CapRoverTheme): Promise<{}> {
|
|
147
147
|
const http = this.http
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
const payload: {
|
|
149
|
+
oldName: string
|
|
150
|
+
name: string
|
|
151
|
+
content: string
|
|
152
|
+
extra?: string
|
|
153
|
+
headEmbed?: string
|
|
154
|
+
} = {
|
|
155
|
+
oldName,
|
|
156
|
+
name: theme.name,
|
|
157
|
+
content: theme.content,
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (theme.extra !== undefined) {
|
|
161
|
+
payload.extra = theme.extra
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (theme.headEmbed !== undefined) {
|
|
165
|
+
payload.headEmbed = theme.headEmbed
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return Promise.resolve() //
|
|
169
|
+
.then(http.fetch(http.POST, '/user/system/themes/update', payload))
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
deleteTheme(themeName: string): Promise<{}> {
|
package/test/ApiManager.test.js
CHANGED
|
@@ -101,3 +101,48 @@ test('executeGenericApiCommand accepts PATCH', async () => {
|
|
|
101
101
|
|
|
102
102
|
assert.equal(requests[0].method, 'PATCH')
|
|
103
103
|
})
|
|
104
|
+
|
|
105
|
+
test('saveTheme sends supplied writable theme fields', async () => {
|
|
106
|
+
const { api, requests } = createApiWithRequestRecorder()
|
|
107
|
+
|
|
108
|
+
await api.saveTheme('old-theme', {
|
|
109
|
+
name: 'new-theme',
|
|
110
|
+
content: 'theme-content',
|
|
111
|
+
extra: '{"siderTheme":"dark"}',
|
|
112
|
+
headEmbed: '<meta name="theme-marker" content="test">',
|
|
113
|
+
builtIn: true,
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
assert.deepEqual(requests, [
|
|
117
|
+
{
|
|
118
|
+
method: 'POST',
|
|
119
|
+
endpoint: '/user/system/themes/update',
|
|
120
|
+
data: {
|
|
121
|
+
oldName: 'old-theme',
|
|
122
|
+
name: 'new-theme',
|
|
123
|
+
content: 'theme-content',
|
|
124
|
+
extra: '{"siderTheme":"dark"}',
|
|
125
|
+
headEmbed: '<meta name="theme-marker" content="test">',
|
|
126
|
+
},
|
|
127
|
+
bodyType: 'json',
|
|
128
|
+
},
|
|
129
|
+
])
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('saveTheme omits unspecified optional theme fields', async () => {
|
|
133
|
+
const { api, requests } = createApiWithRequestRecorder()
|
|
134
|
+
|
|
135
|
+
await api.saveTheme('old-theme', {
|
|
136
|
+
name: 'new-theme',
|
|
137
|
+
content: 'theme-content',
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
assert.deepEqual(requests[0].data, {
|
|
141
|
+
oldName: 'old-theme',
|
|
142
|
+
name: 'new-theme',
|
|
143
|
+
content: 'theme-content',
|
|
144
|
+
})
|
|
145
|
+
assert.equal('extra' in requests[0].data, false)
|
|
146
|
+
assert.equal('headEmbed' in requests[0].data, false)
|
|
147
|
+
assert.equal(JSON.stringify(requests[0].data).includes('undefined'), false)
|
|
148
|
+
})
|