From 2196fe925869de670cf78a71d8bfa76f7564a52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Luba=C5=84ski?= Date: Mon, 26 Oct 2020 19:24:56 +0100 Subject: [PATCH] fix(store): dont rewrite id for list type in async storage --- src/store.js | 8 +++++++- test/spec/store.js | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/store.js b/src/store.js index 45be0b3a..e15989d7 100644 --- a/src/store.js +++ b/src/store.js @@ -83,6 +83,10 @@ function setupStorage(storage) { ); } + if (!result.get && result.list) { + result.get = () => {}; + } + return Object.freeze(result); } @@ -713,7 +717,9 @@ function get(Model, id) { return sync( config, stringId, - config.create(stringId ? { ...data, id: stringId } : data), + config.create( + !config.list && stringId ? { ...data, id: stringId } : data, + ), ); }) .catch(e => { diff --git a/test/spec/store.js b/test/spec/store.js index aef547cf..b2bccd6d 100644 --- a/test/spec/store.js +++ b/test/spec/store.js @@ -1908,6 +1908,21 @@ describe("store:", () => { }); }); + it("returns a list with parameters", done => { + Model = { + id: true, + value: "", + [store.connect]: { + list: () => Promise.resolve([{ id: "1", value: "test" }]), + }, + }; + + store.pending(store.get([Model], { page: 1 })).then(resolvedModel => { + expect(resolvedModel).toEqual([{ id: "1", value: "test" }]); + done(); + }); + }); + it("returns placeholder in async calls for long fetching model", done => { let resolvePromise; Model = {