Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(medusa): move repository specs into its own folder #2952

Merged
merged 6 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration-tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
projects: [
"<rootDir>/integration-tests/api/jest.config.js",
"<rootDir>/integration-tests/plugins/jest.config.js",
"<rootDir>/integration-tests/repositories/jest.config.js",
],
testPathIgnorePatterns: [
`/examples/`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "path"
import { ProductCategory } from "@medusajs/medusa"
import { initDb, useDb } from "../../../helpers/use-db"
import { simpleProductCategoryFactory } from '../../factories'

describe("Product Categories", () => {
let dbConnection
Expand All @@ -21,29 +22,28 @@ describe("Product Categories", () => {
})

describe("Tree Queries (Materialized Paths)", () => {
it("can fetch ancestors, descendents and root product categories", async () => {
const productCategoryRepository = dbConnection.getTreeRepository(ProductCategory)
let a1, a11, a111, a12
let productCategoryRepository

const a1 = productCategoryRepository.create({ name: 'a1', handle: 'a1' })
await productCategoryRepository.save(a1)

const a11 = productCategoryRepository.create({ name: 'a11', handle: 'a11', parent_category: a1 })
await productCategoryRepository.save(a11)

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)
beforeEach(async () => {
a1 = await simpleProductCategoryFactory(dbConnection, { name: 'a1', handle: 'a1' })
a11 = await simpleProductCategoryFactory(dbConnection, { name: 'a11', handle: 'a11', parent_category: a1 })
a111 = await simpleProductCategoryFactory(dbConnection, { name: 'a111', handle: 'a111', parent_category: a11 })
a12 = await simpleProductCategoryFactory(dbConnection, { name: 'a12', handle: 'a12', parent_category: a1 })
productCategoryRepository = dbConnection.getTreeRepository(ProductCategory)
})

it("can fetch all root categories", async () => {
const rootCategories = await productCategoryRepository.findRoots()

expect(rootCategories).toEqual([
expect.objectContaining({
name: "a1",
})
])
})

it("can fetch all ancestors of a category", async () => {
const a11Parent = await productCategoryRepository.findAncestors(a11)

expect(a11Parent).toEqual([
Expand All @@ -54,7 +54,10 @@ describe("Product Categories", () => {
name: "a11",
}),
])
})


it("can fetch all root descendants of a category", async () => {
const a1Children = await productCategoryRepository.findDescendants(a1)

expect(a1Children).toEqual([
Expand Down
1 change: 1 addition & 0 deletions integration-tests/repositories/factories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./simple-product-category-factory"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Connection } from "typeorm"
olivermrbl marked this conversation as resolved.
Show resolved Hide resolved
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 changes: 21 additions & 0 deletions integration-tests/repositories/jest.config.js
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions integration-tests/repositories/medusa-config.js
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions integration-tests/repositories/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@
"lint:docs": "eslint -c docs/.eslintrc.js --ignore-path docs/.eslintignore docs/content",
"prettier": "prettier",
"jest": "jest",
"test": "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",
"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 --filter=integration-tests-repositories",
"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:repositories": "turbo run test --no-daemon --filter=integration-tests-repositories",
"openapi:generate": "node ./scripts/build-openapi.js",
"generate:services": "typedoc --options typedoc.services.js",
"generate:js-client": "typedoc --options typedoc.js-client.js",
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19517,6 +19517,21 @@ __metadata:
languageName: unknown
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":
version: 1.0.3
resolution: "internal-slot@npm:1.0.3"
Expand Down