Fix tests
This commit is contained in:
parent
576ebc997e
commit
39511a4e83
|
@ -70,29 +70,23 @@ describe.each([
|
||||||
let rows: Row[]
|
let rows: Row[]
|
||||||
|
|
||||||
async function basicRelationshipTables(type: RelationshipType) {
|
async function basicRelationshipTables(type: RelationshipType) {
|
||||||
const relatedTable = await createTable(
|
const relatedTable = await createTable({
|
||||||
{
|
name: { name: "name", type: FieldType.STRING },
|
||||||
name: { name: "name", type: FieldType.STRING },
|
})
|
||||||
},
|
const tableId = await createTable({
|
||||||
generator.guid().substring(0, 10)
|
name: { name: "name", type: FieldType.STRING },
|
||||||
)
|
//@ts-ignore - API accepts this structure, will build out rest of definition
|
||||||
const tableId = await createTable(
|
productCat: {
|
||||||
{
|
type: FieldType.LINK,
|
||||||
name: { name: "name", type: FieldType.STRING },
|
relationshipType: type,
|
||||||
//@ts-ignore - API accepts this structure, will build out rest of definition
|
name: "productCat",
|
||||||
productCat: {
|
fieldName: "product",
|
||||||
type: FieldType.LINK,
|
tableId: relatedTable,
|
||||||
relationshipType: type,
|
constraints: {
|
||||||
name: "productCat",
|
type: "array",
|
||||||
fieldName: "product",
|
|
||||||
tableId: relatedTable,
|
|
||||||
constraints: {
|
|
||||||
type: "array",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
generator.guid().substring(0, 10)
|
})
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
relatedTable: await config.api.table.get(relatedTable),
|
relatedTable: await config.api.table.get(relatedTable),
|
||||||
tableId,
|
tableId,
|
||||||
|
@ -138,9 +132,9 @@ describe.each([
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function createTable(schema: TableSchema, name?: string) {
|
async function createTable(schema: TableSchema) {
|
||||||
const table = await config.api.table.save(
|
const table = await config.api.table.save(
|
||||||
tableForDatasource(datasource, { schema, name })
|
tableForDatasource(datasource, { schema })
|
||||||
)
|
)
|
||||||
return table._id!
|
return table._id!
|
||||||
}
|
}
|
||||||
|
@ -157,8 +151,8 @@ describe.each([
|
||||||
["table", createTable],
|
["table", createTable],
|
||||||
[
|
[
|
||||||
"view",
|
"view",
|
||||||
async (schema: TableSchema, name?: string) => {
|
async (schema: TableSchema) => {
|
||||||
const tableId = await createTable(schema, name)
|
const tableId = await createTable(schema)
|
||||||
const view = await config.api.viewV2.create({
|
const view = await config.api.viewV2.create({
|
||||||
tableId: tableId,
|
tableId: tableId,
|
||||||
name: generator.guid(),
|
name: generator.guid(),
|
||||||
|
@ -2042,42 +2036,36 @@ describe.each([
|
||||||
isSql &&
|
isSql &&
|
||||||
describe("related formulas", () => {
|
describe("related formulas", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const arrayTable = await createTable(
|
const arrayTable = await createTable({
|
||||||
{
|
name: { name: "name", type: FieldType.STRING },
|
||||||
name: { name: "name", type: FieldType.STRING },
|
array: {
|
||||||
array: {
|
name: "array",
|
||||||
name: "array",
|
type: FieldType.ARRAY,
|
||||||
type: FieldType.ARRAY,
|
constraints: {
|
||||||
constraints: {
|
type: JsonFieldSubType.ARRAY,
|
||||||
type: JsonFieldSubType.ARRAY,
|
inclusion: ["option 1", "option 2"],
|
||||||
inclusion: ["option 1", "option 2"],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"array"
|
})
|
||||||
)
|
tableOrViewId = await createTableOrView({
|
||||||
tableOrViewId = await createTableOrView(
|
relationship: {
|
||||||
{
|
type: FieldType.LINK,
|
||||||
relationship: {
|
relationshipType: RelationshipType.MANY_TO_ONE,
|
||||||
type: FieldType.LINK,
|
name: "relationship",
|
||||||
relationshipType: RelationshipType.MANY_TO_ONE,
|
fieldName: "relate",
|
||||||
name: "relationship",
|
tableId: arrayTable,
|
||||||
fieldName: "relate",
|
constraints: {
|
||||||
tableId: arrayTable,
|
type: "array",
|
||||||
constraints: {
|
|
||||||
type: "array",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
formula: {
|
|
||||||
type: FieldType.FORMULA,
|
|
||||||
name: "formula",
|
|
||||||
formula: encodeJSBinding(
|
|
||||||
`let array = [];$("relationship").forEach(rel => array = array.concat(rel.array));return array.sort().join(",")`
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"main"
|
formula: {
|
||||||
)
|
type: FieldType.FORMULA,
|
||||||
|
name: "formula",
|
||||||
|
formula: encodeJSBinding(
|
||||||
|
`let array = [];$("relationship").forEach(rel => array = array.concat(rel.array));return array.sort().join(",")`
|
||||||
|
),
|
||||||
|
},
|
||||||
|
})
|
||||||
const arrayRows = await Promise.all([
|
const arrayRows = await Promise.all([
|
||||||
config.api.row.save(arrayTable, {
|
config.api.row.save(arrayTable, {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
@ -2378,12 +2366,9 @@ describe.each([
|
||||||
let relatedTable: string, relatedRows: Row[]
|
let relatedTable: string, relatedRows: Row[]
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
relatedTable = await createTable(
|
relatedTable = await createTable({
|
||||||
{
|
name: { name: "name", type: FieldType.STRING },
|
||||||
name: { name: "name", type: FieldType.STRING },
|
})
|
||||||
},
|
|
||||||
"productCategory"
|
|
||||||
)
|
|
||||||
tableOrViewId = await createTableOrView({
|
tableOrViewId = await createTableOrView({
|
||||||
name: { name: "name", type: FieldType.STRING },
|
name: { name: "name", type: FieldType.STRING },
|
||||||
related1: {
|
related1: {
|
||||||
|
|
Loading…
Reference in New Issue