1
import type { Relation } from '@directus/types';
2
import { expect, test } from 'vitest';
3
import { getRelationType } from './get-relation-type.js';
5
test('Returns null if no relation object is included', () => {
6
const result = getRelationType({ relation: null, collection: null, field: 'test' });
7
expect(result).toBe(null);
10
test('Returns a2o if relation matches and includes one_collection_field and one_allowed_collection', () => {
14
related_collection: null,
16
one_collection_field: 'collection',
17
one_allowed_collections: ['paragraphs', 'headings', 'images'],
21
const result = getRelationType({
27
expect(result).toBe('a2o');
30
test('Returns m2o', () => {
32
collection: 'articles',
34
related_collection: 'authors',
37
const result = getRelationType({
39
collection: 'articles',
43
expect(result).toBe('m2o');
46
test('Returns o2m', () => {
48
collection: 'articles',
50
related_collection: 'authors',
52
one_field: 'articles',
56
const result = getRelationType({
58
collection: 'authors',
62
expect(result).toBe('o2m');
65
test('Returns null when field/collection does not match the relationship', () => {
67
collection: 'articles',
69
related_collection: 'authors',
71
one_field: 'articles',
75
const result = getRelationType({
77
collection: 'unrelated',
81
expect(result).toBe(null);