chore: run prettier on entire test dir

This commit is contained in:
Elliot DeNolf
2022-07-17 08:20:01 -07:00
parent bc9de859c4
commit fa9bd6191c
27 changed files with 181 additions and 245 deletions

View File

@@ -1,24 +1,26 @@
import { buildConfig } from '../buildConfig';
export default buildConfig({
collections: [{
slug: 'arrays',
fields: [
{
name: 'array',
type: 'array',
fields: [
{
type: 'text',
name: 'required',
required: true,
},
{
type: 'text',
name: 'optional',
},
],
},
],
}],
collections: [
{
slug: 'arrays',
fields: [
{
name: 'array',
type: 'array',
fields: [
{
type: 'text',
name: 'required',
required: true,
},
{
type: 'text',
name: 'optional',
},
],
},
],
},
],
});

View File

@@ -36,9 +36,7 @@ describe('array-update', () => {
},
});
const arrayWithExistingValues = [
...doc.array,
];
const arrayWithExistingValues = [...doc.array];
const updatedText = 'this is some new text for the first item in array';
@@ -47,7 +45,6 @@ describe('array-update', () => {
required: updatedText,
};
const updatedDoc = await payload.update<ArrayCollection>({
id: doc.id,
collection,

View File

@@ -6,14 +6,15 @@ export default buildConfig({
admin: {
user: 'users',
},
collections: [{
slug,
auth: {
verify: true,
useAPIKey: true,
maxLoginAttempts: 2,
collections: [
{
slug,
auth: {
verify: true,
useAPIKey: true,
maxLoginAttempts: 2,
},
fields: [],
},
fields: [],
},
],
});

View File

@@ -5,7 +5,6 @@ import { initPayloadTest } from '../helpers/configHelpers';
import { firstRegister } from '../helpers';
import { slug } from './config';
/**
* TODO: Auth
* change password

View File

@@ -2,7 +2,6 @@ import merge from 'deepmerge';
import { Config, SanitizedConfig } from '../src/config/types';
import { buildConfig as buildPayloadConfig } from '../src/config/build';
const baseConfig: Config = {
typescript: {
outputFile: process.env.PAYLOAD_TS_OUTPUT_PATH,
@@ -12,9 +11,10 @@ const baseConfig: Config = {
export function buildConfig(overrides?: Partial<Config>): SanitizedConfig {
if (process.env.NODE_ENV === 'test') {
baseConfig.admin = {
...baseConfig.admin || {},
...(baseConfig.admin || {}),
webpack: (config) => {
const existingConfig = typeof overrides?.admin?.webpack === 'function' ? overrides.admin.webpack(config) : config;
const existingConfig =
typeof overrides?.admin?.webpack === 'function' ? overrides.admin.webpack(config) : config;
return {
...existingConfig,
cache: {
@@ -30,6 +30,5 @@ export function buildConfig(overrides?: Partial<Config>): SanitizedConfig {
baseConfig.admin.disable = true;
}
return buildPayloadConfig(merge(baseConfig, overrides || {}));
}

View File

@@ -191,9 +191,7 @@ describe('collections-graphql', () => {
const response = await client.request(query);
const { docs } = response.Posts;
expect(docs).toContainEqual(
expect.objectContaining({ id: withDescription.id, title: withDescription.title }),
);
expect(docs).toContainEqual(expect.objectContaining({ id: withDescription.id, title: withDescription.title }));
});
it('exists - false', async () => {

View File

@@ -5,27 +5,29 @@ import { buildConfig } from '../buildConfig';
export const slug = 'posts';
export interface Post {
id: string,
title: string,
description: string,
createdAt: Date,
updatedAt: Date,
id: string;
title: string;
description: string;
createdAt: Date;
updatedAt: Date;
}
export default buildConfig({
collections: [{
slug,
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'description',
type: 'text',
},
],
}],
collections: [
{
slug,
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'description',
type: 'text',
},
],
},
],
onInit: async (payload) => {
await payload.create({
collection: 'users',

View File

@@ -64,7 +64,6 @@ describe('collections', () => {
});
});
describe('CRUD', () => {
test('should create', async () => {
await page.goto(url.create);
@@ -182,8 +181,7 @@ describe('collections', () => {
await wait(1000);
await expect(page.locator(tableRowLocator)).toHaveCount(1);
const firstId = await page.locator(tableRowLocator).first().locator('td').first()
.innerText();
const firstId = await page.locator(tableRowLocator).first().locator('td').first().innerText();
expect(firstId).toEqual(id);
// Remove filter

View File

@@ -14,7 +14,7 @@ export interface FieldsRelationship {
id: string;
relationship: RelationOne;
relationshipHasMany: RelationOne[];
relationshipHasManyMultiple: Array<RelationOne | RelationTwo | { relationTo: string, value: string }>;
relationshipHasManyMultiple: Array<RelationOne | RelationTwo | { relationTo: string; value: string }>;
relationshipMultiple: Array<RelationOne | RelationTwo>;
relationshipRestricted: RelationRestricted;
relationshipWithTitle: RelationWithTitle;
@@ -42,7 +42,13 @@ export default buildConfig({
{
slug,
admin: {
defaultColumns: ['id', 'relationship', 'relationshipRestricted', 'relationshipHasManyMultiple', 'relationshipWithTitle'],
defaultColumns: [
'id',
'relationship',
'relationshipRestricted',
'relationshipHasManyMultiple',
'relationshipWithTitle',
],
},
fields: [
{
@@ -170,7 +176,10 @@ export default buildConfig({
data: {
relationship: relationOneDocId,
relationshipRestricted: restrictedDocId,
relationshipHasManyMultiple: relationOneIDs.map((id) => ({ relationTo: relationOneSlug, value: id })),
relationshipHasManyMultiple: relationOneIDs.map((id) => ({
relationTo: relationOneSlug,
value: id,
})),
},
});
});

View File

@@ -12,13 +12,7 @@ import type {
RelationTwo,
RelationWithTitle,
} from './config';
import {
relationOneSlug,
relationRestrictedSlug,
relationTwoSlug,
relationWithTitleSlug,
slug,
} from './config';
import { relationOneSlug, relationRestrictedSlug, relationTwoSlug, relationWithTitleSlug, slug } from './config';
import wait from '../../src/utilities/wait';
const { beforeAll, describe } = test;

View File

@@ -62,9 +62,7 @@ export const blocksField: Field = {
const BlockFields: CollectionConfig = {
slug: 'block-fields',
fields: [
blocksField,
],
fields: [blocksField],
};
export const blocksFieldSeedData = [

View File

@@ -32,5 +32,4 @@ export const conditionalLogicDoc = {
fieldToToggle: 'spiderman',
};
export default ConditionalLogic;

View File

@@ -37,5 +37,4 @@ export const pointDoc = {
group: { point: [1, 9] },
};
export default PointFields;

View File

@@ -166,5 +166,4 @@ export const richTextDoc = {
],
};
export default RichTextFields;

View File

@@ -33,9 +33,7 @@ const TabsFields: CollectionConfig = {
{
label: 'Tab with Blocks',
description: 'Blocks are rendered here to ensure they populate and render correctly.',
fields: [
blocksField,
],
fields: [blocksField],
},
{
label: 'Tab with Group',
@@ -95,7 +93,7 @@ const TabsFields: CollectionConfig = {
export const tabsDoc = {
array: [
{
text: 'Hello, I\'m the first row',
text: "Hello, I'm the first row",
},
{
text: 'Second row here',

View File

@@ -18,5 +18,4 @@ export const textDoc = {
text: 'Seeded text document',
};
export default TextFields;

View File

@@ -4,14 +4,14 @@ import wait from '../src/utilities/wait';
import { devUser } from './credentials';
type FirstRegisterArgs = {
page: Page,
serverURL: string,
}
page: Page;
serverURL: string;
};
type LoginArgs = {
page: Page,
serverURL: string,
}
page: Page;
serverURL: string;
};
export async function firstRegister(args: FirstRegisterArgs): Promise<void> {
const { page, serverURL } = args;

View File

@@ -7,9 +7,9 @@ import type { InitOptions } from '../../src/config/types';
import payload from '../../src';
type Options = {
__dirname: string
init?: Partial<InitOptions>
}
__dirname: string;
init?: Partial<InitOptions>;
};
export async function initPayloadE2E(__dirname: string): Promise<{ serverURL: string }> {
return initPayloadTest({
@@ -25,7 +25,7 @@ export async function initPayloadTest(options: Options): Promise<{ serverURL: st
local: true,
secret: uuid(),
mongoURL: `mongodb://localhost/${uuid()}`,
...options.init || {},
...(options.init || {}),
};
process.env.PAYLOAD_DISABLE_ADMIN = 'true';

View File

@@ -8,46 +8,46 @@ import { devUser } from '../credentials';
require('isomorphic-fetch');
type Args = {
serverURL: string
defaultSlug: string
}
serverURL: string;
defaultSlug: string;
};
type LoginArgs = {
email: string
password: string
collection: string
}
email: string;
password: string;
collection: string;
};
type CreateArgs<T = any> = {
slug?: string
data: T
auth?: boolean
file?: boolean
}
slug?: string;
data: T;
auth?: boolean;
file?: boolean;
};
type FindArgs = {
slug?: string
query?: Where
auth?: boolean
}
slug?: string;
query?: Where;
auth?: boolean;
};
type UpdateArgs<T = any> = {
slug?: string
id: string
data: Partial<T>
auth?: boolean
query?: any
}
slug?: string;
id: string;
data: Partial<T>;
auth?: boolean;
query?: any;
};
type DeleteArgs = {
slug?: string
id: string
auth?: boolean
}
slug?: string;
id: string;
auth?: boolean;
};
type DocResponse<T> = {
status: number
doc: T
}
status: number;
doc: T;
};
const headers = {
'Content-Type': 'application/json',
@@ -148,14 +148,11 @@ export class RESTClient {
if (args?.auth) {
headers.Authorization = `JWT ${this.token}`;
}
const response = await fetch(
`${this.serverURL}/api/${slug || this.defaultSlug}/${id}${formattedQs}`,
{
body: JSON.stringify(data),
headers,
method: 'put',
},
);
const response = await fetch(`${this.serverURL}/api/${slug || this.defaultSlug}/${id}${formattedQs}`, {
body: JSON.stringify(data),
headers,
method: 'put',
});
const { status } = response;
const json = await response.json();
return { status, doc: json.doc };

View File

@@ -7,55 +7,63 @@ const Hooks: CollectionConfig = {
slug: hooksSlug,
access: openAccess,
hooks: {
beforeValidate: [({ data }) => (validateHookOrder('collectionBeforeValidate', data))],
beforeChange: [({ data }) => (validateHookOrder('collectionBeforeChange', data))],
afterChange: [({ doc }) => (validateHookOrder('collectionAfterChange', doc))],
beforeRead: [({ doc }) => (validateHookOrder('collectionBeforeRead', doc))],
afterRead: [({ doc }) => (validateHookOrder('collectionAfterRead', doc))],
beforeValidate: [({ data }) => validateHookOrder('collectionBeforeValidate', data)],
beforeChange: [({ data }) => validateHookOrder('collectionBeforeChange', data)],
afterChange: [({ doc }) => validateHookOrder('collectionAfterChange', doc)],
beforeRead: [({ doc }) => validateHookOrder('collectionBeforeRead', doc)],
afterRead: [({ doc }) => validateHookOrder('collectionAfterRead', doc)],
},
fields: [
{
name: 'fieldBeforeValidate',
type: 'checkbox',
hooks: {
beforeValidate: [({ data }) => {
data.fieldBeforeValidate = true;
validateHookOrder('fieldBeforeValidate', data);
return true;
}],
beforeValidate: [
({ data }) => {
data.fieldBeforeValidate = true;
validateHookOrder('fieldBeforeValidate', data);
return true;
},
],
},
},
{
name: 'fieldBeforeChange',
type: 'checkbox',
hooks: {
beforeChange: [({ data }) => {
data.fieldBeforeChange = true;
validateHookOrder('fieldBeforeChange', data);
return true;
}],
beforeChange: [
({ data }) => {
data.fieldBeforeChange = true;
validateHookOrder('fieldBeforeChange', data);
return true;
},
],
},
},
{
name: 'fieldAfterChange',
type: 'checkbox',
hooks: {
afterChange: [({ data }) => {
data.fieldAfterChange = true;
validateHookOrder('fieldAfterChange', data);
return true;
}],
afterChange: [
({ data }) => {
data.fieldAfterChange = true;
validateHookOrder('fieldAfterChange', data);
return true;
},
],
},
},
{
name: 'fieldAfterRead',
type: 'checkbox',
hooks: {
afterRead: [({ data }) => {
data.fieldAfterRead = true;
validateHookOrder('fieldAfterRead', data);
return true;
}],
afterRead: [
({ data }) => {
data.fieldAfterRead = true;
validateHookOrder('fieldAfterRead', data);
return true;
},
],
},
},
{

View File

@@ -37,9 +37,7 @@ const TransformHooks: CollectionConfig = {
},
],
hooks: {
beforeRead: [
(operation) => operation.doc,
],
beforeRead: [(operation) => operation.doc],
beforeChange: [
(operation) => {
operation.data.beforeChange = !operation.data.location?.coordinates;

View File

@@ -4,10 +4,7 @@ import TransformHooks from './collections/Transform';
import Hooks, { hooksSlug } from './collections/Hook';
export default buildConfig({
collections: [
TransformHooks,
Hooks,
],
collections: [TransformHooks, Hooks],
onInit: async (payload) => {
await payload.create({
collection: hooksSlug,

View File

@@ -65,8 +65,7 @@ export default buildConfig({
},
],
},
fields: [
],
fields: [],
},
{
slug: 'unstored-media',

View File

@@ -27,10 +27,7 @@ describe('Collections - Uploads', () => {
describe('create', () => {
it('creates from form data', async () => {
const formData = new FormData();
formData.append(
'file',
fs.createReadStream(path.join(__dirname, './image.png')),
);
formData.append('file', fs.createReadStream(path.join(__dirname, './image.png')));
const { status, doc } = await client.create({
file: true,
@@ -62,10 +59,7 @@ describe('Collections - Uploads', () => {
it('creates images that do not require all sizes', async () => {
const formData = new FormData();
formData.append(
'file',
fs.createReadStream(path.join(__dirname, './small.png')),
);
formData.append('file', fs.createReadStream(path.join(__dirname, './small.png')));
const { status, doc } = await client.create({
file: true,
@@ -88,10 +82,7 @@ describe('Collections - Uploads', () => {
it('creates media without storing a file', async () => {
const formData = new FormData();
formData.append(
'file',
fs.createReadStream(path.join(__dirname, './small.png')),
);
formData.append('file', fs.createReadStream(path.join(__dirname, './small.png')));
// unstored media
const { status, doc } = await client.create({
@@ -125,10 +116,7 @@ describe('Collections - Uploads', () => {
});
const formData = new FormData();
formData.append(
'file',
fs.createReadStream(path.join(__dirname, './small.png')),
);
formData.append('file', fs.createReadStream(path.join(__dirname, './small.png')));
const { status, doc } = await client.update({
id: mediaDoc.id,
@@ -147,10 +135,7 @@ describe('Collections - Uploads', () => {
it('delete', async () => {
const formData = new FormData();
formData.append(
'file',
fs.createReadStream(path.join(__dirname, './image.png')),
);
formData.append('file', fs.createReadStream(path.join(__dirname, './image.png')));
const { doc } = await client.create({
file: true,

View File

@@ -3,8 +3,10 @@ import { buildConfig } from '../buildConfig';
export const slug = 'slugname';
export default buildConfig({
collections: [{
slug,
fields: [],
}],
collections: [
{
slug,
fields: [],
},
],
});

17
test/versions/e2e.spec.ts Normal file
View File

@@ -0,0 +1,17 @@
/**
* TODO: Versions, 3 separate collections
* - drafts
* - save draft before publishing
* - publish immediately
* - validation should be skipped when creating a draft
*
* - autosave
* - versions (no drafts)
* - version control shown
* - assert version counts increment
* - navigate to versions
* - versions view accurately shows number of versions
* - compare
* - restore version
* - specify locales to show
*/

View File

@@ -1,58 +0,0 @@
import type { Page } from '@playwright/test';
import { expect, test } from '@playwright/test';
import { AdminUrlUtil } from '../helpers/adminUrlUtil';
import { initPayloadTest } from '../helpers/configHelpers';
import { firstRegister } from '../helpers';
import { slug } from './config';
/**
* TODO: Versions, 3 separate collections
* - drafts
* - save draft before publishing
* - publish immediately
* - validation should be skipped when creating a draft
*
* - autosave
* - versions (no drafts)
* - version control shown
* - assert version counts increment
* - navigate to versions
* - versions view accurately shows number of versions
* - compare
* - restore version
* - specify locales to show
*/
const { beforeAll, describe } = test;
let url: AdminUrlUtil;
describe('suite name', () => {
let page: Page;
beforeAll(async ({ browser }) => {
const { serverURL } = await initPayloadTest({
__dirname,
init: {
local: false,
},
});
// await clearDocs(); // Clear any seeded data from onInit
url = new AdminUrlUtil(serverURL, slug);
const context = await browser.newContext();
page = await context.newPage();
await firstRegister({ page, serverURL });
});
// afterEach(async () => {
// });
describe('feature', () => {
it('testname', () => {
expect(1).toEqual(1);
});
});
});