Skip to content

Commit 52bcfa4

Browse files
authored
Enhance the thrown conflict error with the info of the createFullPath and add more tests to verify said flag (#406)
1 parent 898e3af commit 52bcfa4

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/webdav/services/webdav-folder.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export class WebDavFolderService {
5151
// all ancestors MUST already exist, or the method MUST fail
5252
// with a 409 (Conflict) status code
5353
throw new ConflictError(
54-
`Parent folders not found on Internxt Drive at ${WebDavUtils.decodeUrl(parentPath, false)}`,
54+
`Parent folders not found on Internxt Drive at ${WebDavUtils.decodeUrl(parentPath, false)},
55+
createFullPath flag is set to: ${createFullPath}`,
5556
);
5657
}
5758
const folders = parentPath.split('/').filter((f) => f.length > 0);

test/services/config.service.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,56 @@ describe('Config service', () => {
178178
expect(webdavConfigResult).to.be.deep.equal(defaultWebdavConfig);
179179
expect(fsStub).toHaveBeenCalledWith(ConfigService.WEBDAV_CONFIGS_FILE, 'utf8');
180180
});
181+
182+
it('should default to true when webdav config exists but createFullPath property is missing', async () => {
183+
const partialWebdavConfig = {
184+
host: '192.168.1.1',
185+
port: '8080',
186+
protocol: 'https',
187+
timeoutMinutes: 30,
188+
};
189+
const stringConfig = JSON.stringify(partialWebdavConfig);
190+
191+
const fsStub = vi.spyOn(fs, 'readFile').mockResolvedValue(stringConfig);
192+
193+
const webdavConfigResult = await ConfigService.instance.readWebdavConfig();
194+
expect(webdavConfigResult.createFullPath).to.be.equal(true);
195+
expect(webdavConfigResult.host).to.be.equal(partialWebdavConfig.host);
196+
expect(webdavConfigResult.port).to.be.equal(partialWebdavConfig.port);
197+
expect(fsStub).toHaveBeenCalledWith(ConfigService.WEBDAV_CONFIGS_FILE, 'utf8');
198+
});
199+
200+
it('shoud return false when webdav config has createFullPath explicitly set to false', async () => {
201+
const webdavConfig = {
202+
host: '192.168.1.1',
203+
port: '8080',
204+
protocol: 'https',
205+
timeoutMinutes: 30,
206+
createFullPath: false,
207+
};
208+
const stringConfig = JSON.stringify(webdavConfig);
209+
210+
const fsStub = vi.spyOn(fs, 'readFile').mockResolvedValue(stringConfig);
211+
212+
const webdavConfigResult = await ConfigService.instance.readWebdavConfig();
213+
expect(webdavConfigResult.createFullPath).to.be.equal(false);
214+
expect(fsStub).toHaveBeenCalledWith(ConfigService.WEBDAV_CONFIGS_FILE, 'utf8');
215+
});
216+
217+
it('should return true when webdav config has createFullPath explicitly set to true', async () => {
218+
const webdavConfig = {
219+
host: '192.168.1.1',
220+
port: '8080',
221+
protocol: 'https',
222+
timeoutMinutes: 30,
223+
createFullPath: true,
224+
};
225+
const stringConfig = JSON.stringify(webdavConfig);
226+
227+
const fsStub = vi.spyOn(fs, 'readFile').mockResolvedValue(stringConfig);
228+
229+
const webdavConfigResult = await ConfigService.instance.readWebdavConfig();
230+
expect(webdavConfigResult.createFullPath).to.be.equal(true);
231+
expect(fsStub).toHaveBeenCalledWith(ConfigService.WEBDAV_CONFIGS_FILE, 'utf8');
232+
});
181233
});

0 commit comments

Comments
 (0)