Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/field-types/json-object.subtest.js
Show All 32 Lines | with_running_app(async ({ app, rest_api }) => { | ||||
gender: "male", | gender: "male", | ||||
weight: 300, | weight: 300, | ||||
}, | }, | ||||
}; | }; | ||||
const { id } = await rest_api.post( | const { id } = await rest_api.post( | ||||
"/api/v1/collections/seals", | "/api/v1/collections/seals", | ||||
item | item | ||||
); | ); | ||||
assert.deepEqual( | let { name, metadata } = await rest_api.get( | ||||
item, | `/api/v1/collections/seals/${id}` | ||||
(await rest_api.get(`/api/v1/collections/seals/${id}`)).body | |||||
); | ); | ||||
assert.deepEqual({ name, metadata }, item); | |||||
item.metadata.weight = 320; | item.metadata.weight = 320; | ||||
await rest_api.patch(`/api/v1/collections/seals/${id}`, item); | await rest_api.patch(`/api/v1/collections/seals/${id}`, item); | ||||
assert.deepEqual( | |||||
item, | ({ name, metadata } = await rest_api.get( | ||||
(await rest_api.get(`/api/v1/collections/seals/${id}`)).body | `/api/v1/collections/seals/${id}` | ||||
); | )); | ||||
assert.deepEqual({ name, metadata }, item); | |||||
})); | })); | ||||
it("Doesn't allow to post a primitive", async () => | it("Doesn't allow to post a primitive", async () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
setup(app); | setup(app); | ||||
await assert_throws_async( | await assert_throws_async( | ||||
() => | () => | ||||
rest_api.post("/api/v1/collections/seals", { | rest_api.post("/api/v1/collections/seals", { | ||||
Show All 27 Lines | with_running_app(async ({ app, rest_api }) => { | ||||
}); | }); | ||||
let seals = (await rest_api.get("/api/v1/collections/seals")).items; | let seals = (await rest_api.get("/api/v1/collections/seals")).items; | ||||
assert.equal(seals.length, 2); | assert.equal(seals.length, 2); | ||||
seals = (await rest_api.get( | seals = (await rest_api.get( | ||||
"/api/v1/collections/seals?filter[name]=Hoover" | "/api/v1/collections/seals?filter[name]=Hoover" | ||||
)).items; | )).items; | ||||
assert.equal(seals[0].body.name, "Hoover"); | assert.equal(seals[0].name, "Hoover"); | ||||
seals = (await rest_api.get( | seals = (await rest_api.get( | ||||
"/api/v1/collections/seals?filter[metadata][weight]=280" | "/api/v1/collections/seals?filter[metadata][weight]=280" | ||||
)).items; | )).items; | ||||
assert.equal(seals.length, 1); | assert.equal(seals.length, 1); | ||||
assert.equal(seals[0].body.name, "Maksiu"); | assert.equal(seals[0].name, "Maksiu"); | ||||
})); | })); | ||||
it("Respects filter passed to query when value can be parsed as number", async () => | it("Respects filter passed to query when value can be parsed as number", async () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
setup(app); | setup(app); | ||||
const seals = [ | const seals = [ | ||||
{ | { | ||||
Show All 19 Lines | with_running_app(async ({ app, rest_api }) => { | ||||
for (let seal of seals) { | for (let seal of seals) { | ||||
let { items: actual_seals } = await rest_api.get( | let { items: actual_seals } = await rest_api.get( | ||||
`/api/v1/collections/seals?filter[metadata][weight]=${ | `/api/v1/collections/seals?filter[metadata][weight]=${ | ||||
seal.metadata.weight | seal.metadata.weight | ||||
}` | }` | ||||
); | ); | ||||
assert.equal(actual_seals.length, 1); | assert.equal(actual_seals.length, 1); | ||||
assert.equal(actual_seals[0].body.name, seal.name); | assert.equal(actual_seals[0].name, seal.name); | ||||
} | } | ||||
})); | })); | ||||
}); | }); |