feat(medusa, types): Improve DX of model extensions (#4398)
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import path from "path"
|
||||
import formatRegistrationName from "../format-registration-name"
|
||||
import {
|
||||
formatRegistrationName,
|
||||
formatRegistrationNameWithoutNamespace,
|
||||
} from "../format-registration-name"
|
||||
|
||||
describe("formatRegistrationName", () => {
|
||||
const tests = [
|
||||
@@ -32,3 +35,26 @@ describe("formatRegistrationName", () => {
|
||||
expect(res).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe("formatRegistrationNameWithoutNamespace", () => {
|
||||
const tests = [
|
||||
[["medusa-test-dir", "dist", "services", "my-test.js"], "myTest"],
|
||||
[["medusa-test-dir", "dist", "services", "my.js"], "my"],
|
||||
[["services", "my-quite-long-file.js"], "myQuiteLongFile"],
|
||||
[["/", "Users", "seb", "com.medusa.js", "services", "dot.js"], "dot"],
|
||||
[["/", "Users", "seb.rin", "com.medusa.js", "services", "dot.js"], "dot"],
|
||||
[
|
||||
["/", "Users", "seb.rin", "com.medusa.js", "repositories", "dot.js"],
|
||||
"dot",
|
||||
],
|
||||
[["/", "Users", "seb.rin", "com.medusa.js", "models", "dot.js"], "dot"],
|
||||
[["C:", "server", "services", "dot.js"], "dot"],
|
||||
]
|
||||
|
||||
test.each(
|
||||
tests.map(([pathParts, expected]) => [path.join(...pathParts), expected])
|
||||
)("Service %s -> %s", (fn, expected) => {
|
||||
const res = formatRegistrationNameWithoutNamespace(fn)
|
||||
expect(res).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user