Skip to content

Commit

Permalink
chore(plugin-multi-tenant): test suite enhancements (#10732)
Browse files Browse the repository at this point in the history
### What?
Updates test suite multi-tenant config as a better example.

### Why?
So it is easier to follow and write logical tests for in the future.
  • Loading branch information
JarrodMFlesch authored Jan 22, 2025
1 parent be2c482 commit 9a87699
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 224 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Field, FilterOptionsProps, RelationshipField, Where } from 'payload'
import type { Field, FilterOptionsProps, RelationshipField } from 'payload'

import { getTenantFromCookie } from './getTenantFromCookie.js'

Expand All @@ -7,6 +7,7 @@ type AddFilterOptionsToFieldsArgs = {
tenantEnabledCollectionSlugs: string[]
tenantEnabledGlobalSlugs: string[]
}

export function addFilterOptionsToFields({
fields,
tenantEnabledCollectionSlugs,
Expand Down
18 changes: 0 additions & 18 deletions test/plugin-multi-tenant/collections/Links.ts

This file was deleted.

43 changes: 43 additions & 0 deletions test/plugin-multi-tenant/collections/Menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { CollectionConfig } from 'payload'

import { menuSlug } from '../shared.js'

export const Menu: CollectionConfig = {
slug: menuSlug,
admin: {
useAsTitle: 'title',
},
fields: [
{
name: 'title',
label: 'Title',
type: 'text',
required: true,
},
{
name: 'description',
type: 'textarea',
},
{
name: 'menuItems',
label: 'Menu Items',
type: 'array',
fields: [
{
name: 'menuItem',
label: 'Menu Item',
type: 'relationship',
relationTo: 'menu-items',
required: true,
admin: {
description: 'Automatically filtered by selected tenant',
},
},
{
name: 'active',
type: 'checkbox',
},
],
},
],
}
17 changes: 17 additions & 0 deletions test/plugin-multi-tenant/collections/MenuItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { CollectionConfig } from 'payload'

import { menuItemsSlug } from '../shared.js'

export const MenuItems: CollectionConfig = {
slug: menuItemsSlug,
admin: {
useAsTitle: 'name',
},
fields: [
{
name: 'name',
type: 'text',
required: true,
},
],
}
34 changes: 0 additions & 34 deletions test/plugin-multi-tenant/collections/Posts.ts

This file was deleted.

9 changes: 5 additions & 4 deletions test/plugin-multi-tenant/collections/Tenants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export const Tenants: CollectionConfig = {
required: true,
},
{
name: 'slug',
name: 'domain',
type: 'text',
required: true,
},
{
name: 'domain',
type: 'text',
required: true,
type: 'join',
name: 'users',
collection: 'users',
on: 'tenants.tenant',
},
],
}
34 changes: 0 additions & 34 deletions test/plugin-multi-tenant/collections/Users.ts

This file was deleted.

19 changes: 5 additions & 14 deletions test/plugin-multi-tenant/collections/Users/filterOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FilterOptions, Where } from 'payload'
import type { FilterOptions } from 'payload'

import { getTenantFromCookie } from '@payloadcms/plugin-multi-tenant/utilities'

Expand All @@ -9,17 +9,8 @@ export const userFilterOptions: FilterOptions = ({ req }) => {
}

return {
or: [
{
'tenants.tenant': {
equals: selectedTenant,
},
},
{
roles: {
in: ['admin'],
},
},
],
} as Where
'tenants.tenant': {
equals: selectedTenant,
},
}
}
1 change: 1 addition & 0 deletions test/plugin-multi-tenant/components/Icon/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
border-radius: 100%;
height: 18px;
width: 18px;
background-color: var(--theme-error-300);
}

[data-selected-tenant-title="Blue Dog"] #tenant-icon {
Expand Down
1 change: 1 addition & 0 deletions test/plugin-multi-tenant/components/Logo/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
border-radius: 100%;
height: 18px;
width: 18px;
background-color: var(--theme-error-300);
}

[data-selected-tenant-title="Blue Dog"] #tenant-logo {
Expand Down
14 changes: 6 additions & 8 deletions test/plugin-multi-tenant/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ const dirname = path.dirname(filename)
import type { Config as ConfigType } from './payload-types.js'

import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { LinksCollection } from './collections/Links.js'
import { Posts } from './collections/Posts.js'
import { Menu } from './collections/Menu.js'
import { MenuItems } from './collections/MenuItems.js'
import { Tenants } from './collections/Tenants.js'
import { Users } from './collections/Users.js'
import { NavigationGlobalCollection } from './globals/Navigation.js'
import { Users } from './collections/Users/index.js'
import { seed } from './seed/index.js'

export default buildConfigWithDefaults({
collections: [Users, Tenants, Posts, LinksCollection, NavigationGlobalCollection],
collections: [Tenants, Users, Menu, MenuItems],
admin: {
importMap: {
baseDir: path.resolve(dirname),
Expand Down Expand Up @@ -47,9 +46,8 @@ export default buildConfigWithDefaults({
access: {},
},
collections: {
posts: {},
links: {},
'navigation-global': {
'menu-items': {},
menu: {
isGlobal: true,
},
},
Expand Down
14 changes: 0 additions & 14 deletions test/plugin-multi-tenant/globals/Navigation.ts

This file was deleted.

Loading

0 comments on commit 9a87699

Please sign in to comment.