Skip to content

Commit

Permalink
get int test spawnInitProcess scripts to work
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Jul 31, 2024
1 parent e94b498 commit baead05
Show file tree
Hide file tree
Showing 36 changed files with 206 additions and 72 deletions.
8 changes: 6 additions & 2 deletions test/_community/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import type { Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'

import { devUser } from '../credentials.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { postsSlug } from './collections/Posts/index.js'
import configPromise from './config.js'

let payload: Payload
let token: string
let restClient: NextRESTClient

const { email, password } = devUser
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('_Community Tests', () => {
// --__--__--__--__--__--__--__--__--__
// Boilerplate test setup/teardown
// --__--__--__--__--__--__--__--__--__
beforeAll(async () => {
const initialized = await initPayloadInt(configPromise)
const initialized = await initPayloadInt(dirname)
;({ payload, restClient } = initialized)

const data = await restClient
Expand Down
9 changes: 6 additions & 3 deletions test/access-control/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type {
RequiredDataFromCollectionSlug,
} from 'payload'

import path from 'path'
import { Forbidden } from 'payload'
import { fileURLToPath } from 'url'

import type { FullyRestricted, Post } from './payload-types.js'

import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise, { requestHeaders } from './config.js'
import { requestHeaders } from './config.js'
import {
firstArrayText,
fullyRestrictedSlug,
Expand All @@ -26,13 +28,14 @@ import {
} from './shared.js'

let payload: Payload

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
describe('Access Control', () => {
let post1: Post
let restricted: FullyRestricted

beforeAll(async () => {
;({ payload } = await initPayloadInt(configPromise))
;({ payload } = await initPayloadInt(dirname))
})

beforeEach(async () => {
Expand Down
9 changes: 7 additions & 2 deletions test/admin-root/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import type { Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'

import { devUser } from '../credentials.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { postsSlug } from './collections/Posts/index.js'
import configPromise from './config.js'

let payload: Payload
let token: string
let restClient: NextRESTClient

const { email, password } = devUser

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('Admin (Root) Tests', () => {
// --__--__--__--__--__--__--__--__--__
// Boilerplate test setup/teardown
// --__--__--__--__--__--__--__--__--__
beforeAll(async () => {
const initialized = await initPayloadInt(configPromise)
const initialized = await initPayloadInt(dirname)
;({ payload, restClient } = initialized)

const data = await restClient
Expand Down
9 changes: 7 additions & 2 deletions test/array-update/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import type { Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js'
import { arraySlug } from './shared.js'

let payload: Payload

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('array-update', () => {
beforeAll(async () => {
;({ payload } = await initPayloadInt(configPromise))
;({ payload } = await initPayloadInt(dirname))
})

afterAll(async () => {
Expand Down
9 changes: 7 additions & 2 deletions test/auth/custom-strategy/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../../helpers/NextRESTClient.js'

import { initPayloadInt } from '../../helpers/initPayloadInt.js'
import configPromise from './config.js'
import { usersSlug } from './shared.js'

let payload: Payload
Expand All @@ -15,9 +17,12 @@ const headers = {
'Content-Type': 'application/json',
}

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('AuthStrategies', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
;({ payload, restClient } = await initPayloadInt(dirname))
})

afterAll(async () => {
Expand Down
8 changes: 6 additions & 2 deletions test/auth/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import type { Payload, User } from 'payload'

import { jwtDecode } from 'jwt-decode'
import path from 'path'
import { fileURLToPath } from 'url'
import { v4 as uuid } from 'uuid'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'

import { devUser } from '../credentials.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js'
import { apiKeysSlug, namedSaveToJWTValue, saveToJWTKey, slug } from './shared.js'

let restClient: NextRESTClient
let payload: Payload

const { email, password } = devUser

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('Auth', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
;({ payload, restClient } = await initPayloadInt(dirname))
})

afterAll(async () => {
Expand Down
10 changes: 8 additions & 2 deletions test/auth/removed-token/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import type { Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../../helpers/NextRESTClient.js'

import { devUser } from '../../credentials.js'
import { initPayloadInt } from '../../helpers/initPayloadInt.js'
import config, { collectionSlug } from './config.js'
import { collectionSlug } from './config.js'

let restClient: NextRESTClient
let payload: Payload

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('Remove token from auth responses', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(config))
;({ payload, restClient } = await initPayloadInt(dirname))

await restClient.POST(`/${collectionSlug}/first-register`, {
body: JSON.stringify({ ...devUser, 'confirm-password': devUser.password }),
Expand Down
4 changes: 2 additions & 2 deletions test/collections-graphql/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Post } from './payload-types.js'

import { idToString } from '../helpers/idToString.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import config, { errorOnHookSlug, pointSlug, relationSlug, slug } from './config.js'
import { errorOnHookSlug, pointSlug, relationSlug, slug } from './config.js'

const title = 'title'

Expand All @@ -21,7 +21,7 @@ const dirname = path.dirname(filename)

describe('collections-graphql', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(config))
;({ payload, restClient } = await initPayloadInt(dirname))

// Wait for indexes to be created,
// as we need them to query by point
Expand Down
9 changes: 7 additions & 2 deletions test/collections-rest/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { Payload } from 'payload'

import { randomBytes } from 'crypto'
import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'
import type { Relation } from './config.js'
import type { Post } from './payload-types.js'

import { initPayloadInt } from '../helpers/initPayloadInt.js'
import config, {
import {
customIdNumberSlug,
customIdSlug,
errorOnHookSlug,
Expand All @@ -16,12 +18,15 @@ import config, {
slug,
} from './config.js'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

let restClient: NextRESTClient
let payload: Payload

describe('collections-rest', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(config))
;({ payload, restClient } = await initPayloadInt(dirname))

// Wait for indexes to be created,
// as we need them to query by point
Expand Down
9 changes: 7 additions & 2 deletions test/config/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import type { BlockField, Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'

import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js'

let restClient: NextRESTClient
let payload: Payload

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('Config', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
;({ payload, restClient } = await initPayloadInt(dirname))
})

afterAll(async () => {
Expand Down
9 changes: 7 additions & 2 deletions test/custom-graphql/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import type { Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'

import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js'

let restClient: NextRESTClient
let payload: Payload

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('Custom GraphQL', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
;({ payload, restClient } = await initPayloadInt(dirname))
})

afterAll(async () => {
Expand Down
3 changes: 1 addition & 2 deletions test/database/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { fileURLToPath } from 'url'
import { devUser } from '../credentials.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import removeFiles from '../helpers/removeFiles.js'
import configPromise from './config.js'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
Expand All @@ -25,7 +24,7 @@ process.env.PAYLOAD_CONFIG_PATH = path.join(dirname, 'config.ts')

describe('database', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
;({ payload, restClient } = await initPayloadInt(dirname))
payload.db.migrationDir = path.join(dirname, './migrations')

const loginResult = await payload.login({
Expand Down
10 changes: 8 additions & 2 deletions test/dataloader/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import type { Payload } from 'payload'

import path from 'path'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'

import { devUser } from '../credentials.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise, { postDoc } from './config.js'
import { postDoc } from './config.js'

let restClient: NextRESTClient
let payload: Payload
let token: string

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('dataloader', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
;({ payload, restClient } = await initPayloadInt(dirname))

const loginResult = await payload.login({
collection: 'users',
Expand Down
8 changes: 6 additions & 2 deletions test/endpoints/int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import path from 'path'
import { type Payload } from 'payload'
import { fileURLToPath } from 'url'

import type { NextRESTClient } from '../helpers/NextRESTClient.js'

import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js'
import {
applicationEndpoint,
collectionSlug,
Expand All @@ -17,9 +18,12 @@ import {
let payload: Payload
let restClient: NextRESTClient

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

describe('Endpoints', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
;({ payload, restClient } = await initPayloadInt(dirname))
})

afterAll(async () => {
Expand Down
Loading

0 comments on commit baead05

Please sign in to comment.