Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/medusajs/medusa into cho…
Browse files Browse the repository at this point in the history
…re/workflow-passing-context
  • Loading branch information
carlos-r-l-rodrigues committed Jan 31, 2024
2 parents e5ec8d0 + 36ec3ea commit 469234a
Show file tree
Hide file tree
Showing 88 changed files with 3,824 additions and 304 deletions.
46 changes: 33 additions & 13 deletions docs-util/packages/docblock-generator/src/classes/git-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Octokit } from "octokit"
import promiseExec from "../utils/promise-exec.js"
import getMonorepoRoot from "../utils/get-monorepo-root.js"
import filterFiles from "../utils/filter-files.js"

type Options = {
owner?: string
Expand Down Expand Up @@ -52,24 +55,41 @@ export class GitManager {

await Promise.all(
commits.map(async (commit) => {
const {
data: { files: commitFiles },
} = await this.octokit.request(
"GET /repos/{owner}/{repo}/commits/{ref}",
{
owner: this.owner,
repo: this.repo,
ref: commit.sha,
headers: {
"X-GitHub-Api-Version": this.gitApiVersion,
},
}
)
const commitFiles = await this.getCommitFiles(commit.sha)

commitFiles?.forEach((commitFile) => files.add(commitFile.filename))
})
)

return [...files]
}

async getDiffFiles(): Promise<string[]> {
const childProcess = await promiseExec(
`git diff --name-only -- "packages/**/**.ts" "packages/**/*.js" "packages/**/*.tsx" "packages/**/*.jsx"`,
{
cwd: getMonorepoRoot(),
}
)

return filterFiles(
childProcess.stdout.toString().split("\n").filter(Boolean)
)
}

async getCommitFiles(commitSha: string) {
const {
data: { files },
} = await this.octokit.request("GET /repos/{owner}/{repo}/commits/{ref}", {
owner: "medusajs",
repo: "medusa",
ref: commitSha,
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
per_page: 3000,
})

return files
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import path from "path"
import DocblockGenerator from "../classes/docblock-generator.js"
import getMonorepoRoot from "../utils/get-monorepo-root.js"
import promiseExec from "../utils/promise-exec.js"
import filterFiles from "../utils/filter-files.js"
import { GitManager } from "../classes/git-manager.js"

export default async function runGitChanges() {
const monorepoPath = getMonorepoRoot()
// retrieve the changed files under `packages` in the monorepo root.
const childProcess = await promiseExec(
`git diff --name-only -- "packages/**/**.ts" "packages/**/*.js" "packages/**/*.tsx" "packages/**/*.jsx"`,
{
cwd: monorepoPath,
}
)

let files = filterFiles(
childProcess.stdout.toString().split("\n").filter(Boolean)
)
const gitManager = new GitManager()
let files = await gitManager.getDiffFiles()

if (!files.length) {
console.log(`No file changes detected.`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
import { Octokit } from "@octokit/core"
import filterFiles from "../utils/filter-files.js"
import path from "path"
import getMonorepoRoot from "../utils/get-monorepo-root.js"
import DocblockGenerator from "../classes/docblock-generator.js"
import { GitManager } from "../classes/git-manager.js"

export default async function (commitSha: string) {
const monorepoPath = getMonorepoRoot()
// retrieve the files changed in the commit
const octokit = new Octokit({
auth: process.env.GH_TOKEN,
})
const gitManager = new GitManager()

const {
data: { files },
} = await octokit.request("GET /repos/{owner}/{repo}/commits/{ref}", {
owner: "medusajs",
repo: "medusa",
ref: commitSha,
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
})
const files = await gitManager.getCommitFiles(commitSha)

// filter changed files
let filteredFiles = filterFiles(files?.map((file) => file.filename) || [])
Expand Down
71 changes: 71 additions & 0 deletions integration-tests/plugins/__tests__/cart/store/get-cart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICartModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"

const env = { MEDUSA_FF_MEDUSA_V2: true }

describe("GET /store/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let cartModuleService: ICartModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await adminSeeder(dbConnection)
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should get cart", async () => {
const cart = await cartModuleService.create({
currency_code: "usd",
items: [
{
unit_price: 1000,
quantity: 1,
title: "Test item",
},
],
})

const api = useApi() as any
const response = await api.get(`/store/carts/${cart.id}`)

expect(response.status).toEqual(200)
expect(response.data.cart).toEqual(
expect.objectContaining({
id: cart.id,
currency_code: "usd",
items: expect.arrayContaining([
expect.objectContaining({
unit_price: 1000,
quantity: 1,
title: "Test item",
}),
]),
})
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}

describe("POST /admin/customer-groups", () => {
let dbConnection
let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await adminSeeder(dbConnection)
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should create a customer group", async () => {
const api = useApi() as any
const response = await api.post(
`/admin/customer-groups`,
{
name: "VIP",
},
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.customer_group).toEqual(
expect.objectContaining({
id: expect.any(String),
name: "VIP",
created_by: "admin_user",
})
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}

describe("DELETE /admin/customer-groups/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await adminSeeder(dbConnection)
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should delete a group", async () => {
const group = await customerModuleService.createCustomerGroup({
name: "VIP",
})

const api = useApi() as any
const response = await api.delete(
`/admin/customer-groups/${group.id}`,
adminHeaders
)

expect(response.status).toEqual(200)

const deletedCustomer = await customerModuleService.retrieveCustomerGroup(
group.id,
{ withDeleted: true }
)
expect(deletedCustomer.deleted_at).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("GET /admin/customer-groups", () => {

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.groups).toEqual([
expect(response.data.customer_groups).toEqual([
expect.objectContaining({
id: expect.any(String),
name: "Test",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}

describe("GET /admin/customer-groups/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await adminSeeder(dbConnection)
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should retrieve customer group", async () => {
const group = await customerModuleService.createCustomerGroup({
name: "Test",
})

const api = useApi() as any
const response = await api.get(
`/admin/customer-groups/${group.id}`,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.customer_group).toEqual(
expect.objectContaining({
id: expect.any(String),
name: "Test",
})
)
})
})

0 comments on commit 469234a

Please sign in to comment.