do not double encode the value

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-09-07 09:45:43 +02:00
parent 46cda8068d
commit 9018da59a9
9 changed files with 34 additions and 32 deletions
@@ -49,14 +49,6 @@ describe('Persistent Storage API', () => {
});
};
beforeEach(() => {
server.use(
rest.get(`${mockBaseUrl}/buckets/`, async (_req, res, ctx) => {
return res(ctx.json([]));
}),
);
});
afterEach(() => {
jest.resetAllMocks();
});
@@ -90,7 +82,8 @@ describe('Persistent Storage API', () => {
`${mockBaseUrl}/buckets/:bucket/keys/:key`,
async (req, res, ctx) => {
const body = await req.json();
const data = { value: JSON.stringify(dummyValue) };
const data = { value: dummyValue };
expect(body).toEqual(data);
return res(ctx.json(data));
@@ -113,7 +106,7 @@ describe('Persistent Storage API', () => {
`${mockBaseUrl}/buckets/:bucket/keys/:key`,
async (req, res, ctx) => {
const body = await req.json();
const data = { value: JSON.stringify(dummyValue) };
const data = { value: dummyValue };
expect(body).toEqual(data);
return res(ctx.json(data));
@@ -136,7 +129,7 @@ describe('Persistent Storage API', () => {
`${mockBaseUrl}/buckets/:bucket/keys/:key`,
async (req, res, ctx) => {
const body = await req.json();
const data = { value: JSON.stringify(mockData) };
const data = { value: mockData };
expect(body).toEqual(data);
return res(ctx.json(data));
@@ -315,7 +308,7 @@ describe('Persistent Storage API', () => {
rest.get(
`${mockBaseUrl}/buckets/:bucket/keys/:key`,
async (_req, res, ctx) => {
return res(ctx.text(JSON.stringify({ value: JSON.stringify(data) })));
return res(ctx.json({ value: data }));
},
),
);
@@ -106,7 +106,7 @@ export class UserSettingsStorage implements StorageApi {
async set<T extends JsonValue>(key: string, data: T): Promise<void> {
const fetchUrl = await this.getFetchUrl(key);
const body = JSON.stringify({ value: JSON.stringify(data) });
const body = JSON.stringify({ value: data });
const response = await this.fetchApi.fetch(fetchUrl, {
method: 'PUT',
@@ -121,7 +121,7 @@ export class UserSettingsStorage implements StorageApi {
this.notifyChanges({
key,
value: JSON.parse(value),
value,
presence: 'present',
});
}
@@ -165,7 +165,7 @@ export class UserSettingsStorage implements StorageApi {
try {
const { value: rawValue } = await response.json();
const value = JSON.parse(rawValue, (_key, val) => {
const value = JSON.parse(JSON.stringify(rawValue), (_key, val) => {
if (typeof val === 'object' && val !== null) {
Object.freeze(val);
}