refactor(medusa): move repository specs into its own folder (#2952)
**What:** Introduces a new folder under which repository specs will be placed. Why: We don't currently have a good place to test ORM logic or custom queries against the database. The repository folder tests are a place for just exactly that. How: Creates an internal package similar to other integration tests - api and plugins. CORE-965
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
"access": "public",
|
"access": "public",
|
||||||
"baseBranch": "master",
|
"baseBranch": "master",
|
||||||
"updateInternalDependencies": "patch",
|
"updateInternalDependencies": "patch",
|
||||||
"ignore": ["integration-tests-api", "integration-tests-plugins"],
|
"ignore": ["integration-tests-api", "integration-tests-plugins", "integration-tests-repositories"],
|
||||||
"snapshot": {
|
"snapshot": {
|
||||||
"useCalculatedVersion": true
|
"useCalculatedVersion": true
|
||||||
}
|
}
|
||||||
|
|||||||
48
.github/workflows/action.yml
vendored
48
.github/workflows/action.yml
vendored
@@ -179,3 +179,51 @@ jobs:
|
|||||||
run: yarn test:integration:plugins
|
run: yarn test:integration:plugins
|
||||||
env:
|
env:
|
||||||
DB_PASSWORD: postgres
|
DB_PASSWORD: postgres
|
||||||
|
|
||||||
|
integration-tests-repositories:
|
||||||
|
needs: setup
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres
|
||||||
|
env:
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 1s
|
||||||
|
--health-timeout 10s
|
||||||
|
--health-retries 10
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Cancel Previous Runs
|
||||||
|
uses: styfle/cancel-workflow-action@0.9.1
|
||||||
|
with:
|
||||||
|
access_token: ${{ github.token }}
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2.3.5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js environment
|
||||||
|
uses: actions/setup-node@v2.4.1
|
||||||
|
with:
|
||||||
|
node-version: "14"
|
||||||
|
cache: "yarn"
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: ./.github/actions/cache-deps
|
||||||
|
with:
|
||||||
|
extension: pipeline
|
||||||
|
|
||||||
|
- name: Run repository integration tests
|
||||||
|
run: yarn test:integration:repositories
|
||||||
|
env:
|
||||||
|
DB_PASSWORD: postgres
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ module.exports = {
|
|||||||
projects: [
|
projects: [
|
||||||
"<rootDir>/integration-tests/api/jest.config.js",
|
"<rootDir>/integration-tests/api/jest.config.js",
|
||||||
"<rootDir>/integration-tests/plugins/jest.config.js",
|
"<rootDir>/integration-tests/plugins/jest.config.js",
|
||||||
|
"<rootDir>/integration-tests/repositories/jest.config.js",
|
||||||
],
|
],
|
||||||
testPathIgnorePatterns: [
|
testPathIgnorePatterns: [
|
||||||
`/examples/`,
|
`/examples/`,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { ProductCategory } from "@medusajs/medusa"
|
import { ProductCategory } from "@medusajs/medusa"
|
||||||
import { initDb, useDb } from "../../../helpers/use-db"
|
import { initDb, useDb } from "../../../helpers/use-db"
|
||||||
|
import { simpleProductCategoryFactory } from '../../factories'
|
||||||
|
|
||||||
describe("Product Categories", () => {
|
describe("Product Categories", () => {
|
||||||
let dbConnection
|
let dbConnection
|
||||||
@@ -21,21 +22,18 @@ describe("Product Categories", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Tree Queries (Materialized Paths)", () => {
|
describe("Tree Queries (Materialized Paths)", () => {
|
||||||
it("can fetch ancestors, descendents and root product categories", async () => {
|
let a1, a11, a111, a12
|
||||||
const productCategoryRepository = dbConnection.getTreeRepository(ProductCategory)
|
let productCategoryRepository
|
||||||
|
|
||||||
const a1 = productCategoryRepository.create({ name: 'a1', handle: 'a1' })
|
beforeEach(async () => {
|
||||||
await productCategoryRepository.save(a1)
|
a1 = await simpleProductCategoryFactory(dbConnection, { name: 'a1', handle: 'a1' })
|
||||||
|
a11 = await simpleProductCategoryFactory(dbConnection, { name: 'a11', handle: 'a11', parent_category: a1 })
|
||||||
const a11 = productCategoryRepository.create({ name: 'a11', handle: 'a11', parent_category: a1 })
|
a111 = await simpleProductCategoryFactory(dbConnection, { name: 'a111', handle: 'a111', parent_category: a11 })
|
||||||
await productCategoryRepository.save(a11)
|
a12 = await simpleProductCategoryFactory(dbConnection, { name: 'a12', handle: 'a12', parent_category: a1 })
|
||||||
|
productCategoryRepository = dbConnection.getTreeRepository(ProductCategory)
|
||||||
const a111 = productCategoryRepository.create({ name: 'a111', handle: 'a111', parent_category: a11 })
|
})
|
||||||
await productCategoryRepository.save(a111)
|
|
||||||
|
|
||||||
const a12 = productCategoryRepository.create({ name: 'a12', handle: 'a12', parent_category: a1 })
|
|
||||||
await productCategoryRepository.save(a12)
|
|
||||||
|
|
||||||
|
it("can fetch all root categories", async () => {
|
||||||
const rootCategories = await productCategoryRepository.findRoots()
|
const rootCategories = await productCategoryRepository.findRoots()
|
||||||
|
|
||||||
expect(rootCategories).toEqual([
|
expect(rootCategories).toEqual([
|
||||||
@@ -43,7 +41,9 @@ describe("Product Categories", () => {
|
|||||||
name: "a1",
|
name: "a1",
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can fetch all ancestors of a category", async () => {
|
||||||
const a11Parent = await productCategoryRepository.findAncestors(a11)
|
const a11Parent = await productCategoryRepository.findAncestors(a11)
|
||||||
|
|
||||||
expect(a11Parent).toEqual([
|
expect(a11Parent).toEqual([
|
||||||
@@ -54,7 +54,10 @@ describe("Product Categories", () => {
|
|||||||
name: "a11",
|
name: "a11",
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it("can fetch all root descendants of a category", async () => {
|
||||||
const a1Children = await productCategoryRepository.findDescendants(a1)
|
const a1Children = await productCategoryRepository.findDescendants(a1)
|
||||||
|
|
||||||
expect(a1Children).toEqual([
|
expect(a1Children).toEqual([
|
||||||
1
integration-tests/repositories/factories/index.ts
Normal file
1
integration-tests/repositories/factories/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from "./simple-product-category-factory"
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { Connection } from "typeorm"
|
||||||
|
import { ProductCategory } from "@medusajs/medusa"
|
||||||
|
|
||||||
|
export const simpleProductCategoryFactory = async (
|
||||||
|
connection: Connection,
|
||||||
|
data: Partial<ProductCategory> = {}
|
||||||
|
): Promise<ProductCategory> => {
|
||||||
|
const manager = connection.manager
|
||||||
|
const address = manager.create(ProductCategory, data)
|
||||||
|
|
||||||
|
return await manager.save(address)
|
||||||
|
}
|
||||||
21
integration-tests/repositories/jest.config.js
Normal file
21
integration-tests/repositories/jest.config.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: "repositories",
|
||||||
|
testEnvironment: `node`,
|
||||||
|
rootDir: "./",
|
||||||
|
testTimeout: 10000,
|
||||||
|
testPathIgnorePatterns: [
|
||||||
|
`/examples/`,
|
||||||
|
`/www/`,
|
||||||
|
`/dist/`,
|
||||||
|
`/node_modules/`,
|
||||||
|
`__tests__/fixtures`,
|
||||||
|
`__testfixtures__`,
|
||||||
|
`.cache`,
|
||||||
|
],
|
||||||
|
transformIgnorePatterns: [`/dist`],
|
||||||
|
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
||||||
|
setupFiles: ["../setup-env.js"],
|
||||||
|
setupFilesAfterEnv: ["../setup.js"],
|
||||||
|
globalSetup: "../globalSetup.js",
|
||||||
|
globalTeardown: "../globalTeardown.js",
|
||||||
|
}
|
||||||
15
integration-tests/repositories/medusa-config.js
Normal file
15
integration-tests/repositories/medusa-config.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const DB_HOST = process.env.DB_HOST
|
||||||
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
|
const DB_NAME = process.env.DB_TEMP_NAME
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
plugins: [],
|
||||||
|
projectConfig: {
|
||||||
|
redis_url: process.env.REDIS_URL,
|
||||||
|
database_url: `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`,
|
||||||
|
database_type: "postgres",
|
||||||
|
jwt_secret: "test",
|
||||||
|
cookie_secret: "test",
|
||||||
|
},
|
||||||
|
}
|
||||||
22
integration-tests/repositories/package.json
Normal file
22
integration-tests/repositories/package.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "integration-tests-repositories",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest --silent=false --runInBand --bail --detectOpenHandles --forceExit"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@medusajs/medusa": "*",
|
||||||
|
"medusa-interfaces": "*",
|
||||||
|
"typeorm": "^0.2.31"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/cli": "^7.12.10",
|
||||||
|
"@babel/core": "^7.12.10",
|
||||||
|
"@babel/node": "^7.12.10",
|
||||||
|
"babel-preset-medusa-package": "*",
|
||||||
|
"jest": "^26.6.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,10 +66,11 @@
|
|||||||
"lint:docs": "eslint -c docs/.eslintrc.js --ignore-path docs/.eslintignore docs/content",
|
"lint:docs": "eslint -c docs/.eslintrc.js --ignore-path docs/.eslintignore docs/content",
|
||||||
"prettier": "prettier",
|
"prettier": "prettier",
|
||||||
"jest": "jest",
|
"jest": "jest",
|
||||||
"test": "turbo run test --no-daemon --filter=!integration-tests-api --filter=!integration-tests-plugins",
|
"test": "turbo run test --no-daemon --filter=!integration-tests-api --filter=!integration-tests-plugins --filter=!integration-tests-repositories",
|
||||||
"test:integration": "turbo run test --no-daemon --filter=integration-tests-api --filter=integration-tests-plugins",
|
"test:integration": "turbo run test --no-daemon --filter=integration-tests-api --filter=integration-tests-plugins --filter=integration-tests-repositories",
|
||||||
"test:integration:api": "turbo run test --no-daemon --filter=integration-tests-api",
|
"test:integration:api": "turbo run test --no-daemon --filter=integration-tests-api",
|
||||||
"test:integration:plugins": "turbo run test --no-daemon --filter=integration-tests-plugins",
|
"test:integration:plugins": "turbo run test --no-daemon --filter=integration-tests-plugins",
|
||||||
|
"test:integration:repositories": "turbo run test --no-daemon --filter=integration-tests-repositories",
|
||||||
"openapi:generate": "node ./scripts/build-openapi.js",
|
"openapi:generate": "node ./scripts/build-openapi.js",
|
||||||
"generate:services": "typedoc --options typedoc.services.js",
|
"generate:services": "typedoc --options typedoc.services.js",
|
||||||
"generate:js-client": "typedoc --options typedoc.js-client.js",
|
"generate:js-client": "typedoc --options typedoc.js-client.js",
|
||||||
|
|||||||
15
yarn.lock
15
yarn.lock
@@ -19517,6 +19517,21 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
"integration-tests-repositories@workspace:integration-tests/repositories":
|
||||||
|
version: 0.0.0-use.local
|
||||||
|
resolution: "integration-tests-repositories@workspace:integration-tests/repositories"
|
||||||
|
dependencies:
|
||||||
|
"@babel/cli": ^7.12.10
|
||||||
|
"@babel/core": ^7.12.10
|
||||||
|
"@babel/node": ^7.12.10
|
||||||
|
"@medusajs/medusa": "*"
|
||||||
|
babel-preset-medusa-package: "*"
|
||||||
|
jest: ^26.6.3
|
||||||
|
medusa-interfaces: "*"
|
||||||
|
typeorm: ^0.2.31
|
||||||
|
languageName: unknown
|
||||||
|
linkType: soft
|
||||||
|
|
||||||
"internal-slot@npm:^1.0.3":
|
"internal-slot@npm:^1.0.3":
|
||||||
version: 1.0.3
|
version: 1.0.3
|
||||||
resolution: "internal-slot@npm:1.0.3"
|
resolution: "internal-slot@npm:1.0.3"
|
||||||
|
|||||||
Reference in New Issue
Block a user