From 91eab0550c99e05e3f5afaab5f82b1317daaacd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Thu, 30 Jul 2020 23:57:13 +0200 Subject: [PATCH] fix: exporting only feature toggles as yaml should not crash fixes #615 --- lib/routes/admin-api/state.js | 4 +++- test/e2e/api/admin/state.e2e.test.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/routes/admin-api/state.js b/lib/routes/admin-api/state.js index 3d42bd605a..a2900bcf79 100644 --- a/lib/routes/admin-api/state.js +++ b/lib/routes/admin-api/state.js @@ -69,7 +69,9 @@ class StateController extends Controller { if (downloadFile) { res.attachment(`export-${timestamp}.yml`); } - res.type('yaml').send(YAML.safeDump(data)); + res.type('yaml').send( + YAML.safeDump(data, { skipInvalid: true }), + ); } else { if (downloadFile) { res.attachment(`export-${timestamp}.json`); diff --git a/test/e2e/api/admin/state.e2e.test.js b/test/e2e/api/admin/state.e2e.test.js index 1d60310f16..86b9452c8b 100644 --- a/test/e2e/api/admin/state.e2e.test.js +++ b/test/e2e/api/admin/state.e2e.test.js @@ -39,6 +39,15 @@ test.serial('exports strategies and features as yaml', async t => { .expect(200); }); +test.serial('exports only features as yaml', async t => { + t.plan(0); + const request = await setupApp(stores); + return request + .get('/api/admin/state/export?format=yaml&featureToggles=1') + .expect('Content-Type', /yaml/) + .expect(200); +}); + test.serial('exports strategies and features as attachment', async t => { t.plan(0); const request = await setupApp(stores);