Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/field-types/reverse-single-reference.subtest.js
const assert = require("assert"); | |||||
const Promise = require("bluebird"); | |||||
const locreq = require("locreq")(__dirname); | const locreq = require("locreq")(__dirname); | ||||
const axios = require("axios"); | const assert = require("assert"); | ||||
const { create_resource_as } = locreq("test_utils"); | const { with_stopped_app } = locreq("test_utils/with-test-app.js"); | ||||
const { with_stopped_app, with_running_app } = locreq( | |||||
"test_utils/with-test-app.js" | |||||
); | |||||
const DatastoreMongoFactory = locreq("lib/datastore/db.js"); | |||||
describe("reverse-single-reference", () => { | describe("reverse-single-reference", () => { | ||||
/* eslint-disable no-shadow */ | |||||
async function create_referencing_collections(app, with_reverse) { | async function create_referencing_collections(app, with_reverse) { | ||||
const A = app.createChip(app.Sealious.Collection, { | const A = app.createChip(app.Sealious.Collection, { | ||||
name: "A", | name: "A", | ||||
fields: [ | fields: [ | ||||
{ | { | ||||
name: "reference_to_b", | name: "reference_to_b", | ||||
type: "single_reference", | type: "single_reference", | ||||
params: { collection: "B" }, | params: { collection: "B" }, | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | with_reverse(async ({ app, rest_api }) => { | ||||
const { | const { | ||||
items: [new_result1], | items: [new_result1], | ||||
} = await rest_api.get("/api/v1/collections/B?filter[number]=1"); | } = await rest_api.get("/api/v1/collections/B?filter[number]=1"); | ||||
assert.equal(new_result1.references_in_a.length, 2); | assert.equal(new_result1.references_in_a.length, 2); | ||||
})); | })); | ||||
it("updates the cached value when an old reference is edited to an empty one", async () => | it("updates the cached value when an old reference is edited to an empty one", async () => | ||||
with_reverse(async ({ app, rest_api }) => { | with_reverse(async ({ app, rest_api }) => { | ||||
const { | await rest_api.get("/api/v1/collections/B?filter[number]=1"); | ||||
items: [result1], | |||||
} = await rest_api.get("/api/v1/collections/B?filter[number]=1"); | |||||
const { | const { | ||||
items: [result2], | items: [result2], | ||||
} = await rest_api.get("/api/v1/collections/B?filter[number]=2"); | } = await rest_api.get("/api/v1/collections/B?filter[number]=2"); | ||||
const referencing_id = result2.references_in_a[0]; | const referencing_id = result2.references_in_a[0]; | ||||
await rest_api.patch(`/api/v1/collections/A/${referencing_id}`, { | await rest_api.patch(`/api/v1/collections/A/${referencing_id}`, { | ||||
reference_to_b: "", | reference_to_b: "", | ||||
}); | }); | ||||
Show All 30 Lines |