* added NoteService and related endpoints && tests * removed snapshots * corrected error in service * removed snapshot * added the ability to note down author using a string * updated model for note * refactored to access logged in user * added other user id option * removed snapshot * updated according to feedback * removed snapshots * reintroduced snapshots * updated to snake case * removed try catch from use-db
74 lines
1.5 KiB
JavaScript
74 lines
1.5 KiB
JavaScript
const { dropDatabase, createDatabase } = require("pg-god")
|
|
const { createConnection } = require("typeorm")
|
|
|
|
const path = require("path")
|
|
|
|
const DbTestUtil = {
|
|
db_: null,
|
|
|
|
setDb: function (connection) {
|
|
this.db_ = connection
|
|
},
|
|
|
|
clear: function () {
|
|
return this.db_.synchronize(true)
|
|
},
|
|
|
|
shutdown: async function () {
|
|
await this.db_.close()
|
|
return dropDatabase({ databaseName })
|
|
},
|
|
}
|
|
|
|
const instance = DbTestUtil
|
|
|
|
module.exports = {
|
|
initDb: async function ({ cwd }) {
|
|
const migrationDir = path.resolve(
|
|
path.join(
|
|
cwd,
|
|
`node_modules`,
|
|
`@medusajs`,
|
|
`medusa`,
|
|
`dist`,
|
|
`migrations`
|
|
)
|
|
)
|
|
|
|
const databaseName = "medusa-fixtures"
|
|
await createDatabase({ databaseName })
|
|
|
|
const connection = await createConnection({
|
|
type: "postgres",
|
|
url: "postgres://localhost/medusa-fixtures",
|
|
migrations: [`${migrationDir}/*.js`],
|
|
})
|
|
|
|
await connection.runMigrations()
|
|
await connection.close()
|
|
|
|
const modelsLoader = require(path.join(
|
|
cwd,
|
|
`node_modules`,
|
|
`@medusajs`,
|
|
`medusa`,
|
|
`dist`,
|
|
`loaders`,
|
|
`models`
|
|
)).default
|
|
|
|
const entities = modelsLoader({}, { register: false })
|
|
const dbConnection = await createConnection({
|
|
type: "postgres",
|
|
url: "postgres://localhost/medusa-fixtures",
|
|
entities,
|
|
})
|
|
|
|
instance.setDb(dbConnection)
|
|
return dbConnection
|
|
},
|
|
useDb: function () {
|
|
return instance
|
|
},
|
|
}
|