forked from SoftwareBrothers/adminjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add new test application under
app
This app will be launched for different adapters and plugins. It's goal will be to test all kind of interactions for multiple plugin/adapter configurations. And it is written in typescript so types will be checked as well
- Loading branch information
1 parent
1c2ad8f
commit a121c91
Showing
21 changed files
with
5,558 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POSTGRES_USER="adminbro" | ||
POSTGRES_PASSWORD="adminbro" | ||
POSTGRES_DATABASE="adminbro-app" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const admin_bro_1 = __importDefault(require("admin-bro")); | ||
const sequelize_1 = __importDefault(require("@admin-bro/sequelize")); | ||
const user_resource_1 = require("./admin/resources/user/user-resource"); | ||
const sequelize_2 = require("./databases/sequelize"); | ||
const express_1 = require("./plugins/express"); | ||
const options_1 = require("./admin/options"); | ||
admin_bro_1.default.registerAdapter(sequelize_1.default); | ||
const run = async () => { | ||
await sequelize_2.connect(); | ||
const admin = new admin_bro_1.default(Object.assign(Object.assign({}, options_1.options), { resources: [{ | ||
options: user_resource_1.UserResource, | ||
resource: sequelize_2.models.User, | ||
}] })); | ||
express_1.listen(admin); | ||
}; | ||
run(); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"ignore": ["cypress/**/*.js"], | ||
"ext": "js", | ||
"watch": [ | ||
"../lib", | ||
"./build" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "app", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "yarn build && node build/index.js", | ||
"dev": "concurrently \"yarn build --watch\" \"nodemon node build/src/index.js\"", | ||
"cypress:open": "cypress open", | ||
"cypress:run": "cypress run" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.7", | ||
"concurrently": "^5.2.0", | ||
"cypress": "^4.11.0", | ||
"nodemon": "^2.0.4", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.7" | ||
}, | ||
"dependencies": { | ||
"@admin-bro/express": "^3.0.0", | ||
"@admin-bro/sequelize": "1.0.0-beta.5", | ||
"admin-bro": "^3.1.1", | ||
"dotenv": "^8.2.0", | ||
"express": "^4.17.1", | ||
"express-formidable": "^1.2.0", | ||
"express-session": "^1.17.1", | ||
"morgan": "^1.10.0", | ||
"pg": "^8.3.0", | ||
"sequelize": "^6.3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AdminBroOptions } from 'admin-bro' | ||
|
||
const rootPath = '/admin' | ||
|
||
export const options: AdminBroOptions = { | ||
rootPath, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ResourceOptions } from 'admin-bro' | ||
|
||
export const UserResource: ResourceOptions = { | ||
navigation: { | ||
name: 'ala', | ||
icon: 'User', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type AvailableModels = 'User' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Sequelize } from 'sequelize' | ||
|
||
const { | ||
POSTGRES_USER, | ||
POSTGRES_PASSWORD, | ||
POSTGRES_DATABASE, | ||
POSTGRES_PORT, | ||
POSTGRES_HOST, | ||
} = process.env | ||
const sequelizeUrl = [ | ||
'postgres://', POSTGRES_USER, ':', POSTGRES_PASSWORD, '@', POSTGRES_HOST, ':', POSTGRES_PORT, | ||
'/', POSTGRES_DATABASE, | ||
].join('') | ||
|
||
export const sequelize = new Sequelize(sequelizeUrl) | ||
|
||
export const connect = async () => { | ||
try { | ||
await sequelize.authenticate() | ||
console.log('Connection has been established successfully.') | ||
} catch (error) { | ||
console.error('Unable to connect to the database:', error) | ||
} | ||
|
||
await sequelize.sync({ force: true }) | ||
return sequelize | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './connect' | ||
export * from './models' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { AvailableModels } from '../models.type' | ||
import { UserModel } from './user-model' | ||
|
||
export const models: Record<AvailableModels, any> = { | ||
User: UserModel, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DataTypes, Model } from 'sequelize' | ||
import { sequelize } from './connect' | ||
|
||
export interface UserInterface extends Model { | ||
id: string; | ||
firstName: string; | ||
lastName?: string; | ||
} | ||
|
||
export const UserModel = sequelize.define<UserInterface>('User', { | ||
// Model attributes are defined here | ||
firstName: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
lastName: { | ||
type: DataTypes.STRING, | ||
}, | ||
}, { | ||
// Other model options go here | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
import AdminBro from 'admin-bro' | ||
import AdminBroSequelize from '@admin-bro/sequelize' | ||
import { UserResource } from './admin/resources/user/user-resource' | ||
|
||
import { connect, models } from './databases/sequelize' | ||
import { listen } from './plugins/express' | ||
import { options } from './admin/options' | ||
|
||
AdminBro.registerAdapter(AdminBroSequelize) | ||
|
||
const run = async (): Promise<void> => { | ||
await connect() | ||
|
||
const admin = new AdminBro({ | ||
...options, | ||
resources: [{ | ||
options: UserResource, | ||
resource: models.User, | ||
}], | ||
}) | ||
|
||
listen(admin) | ||
} | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { buildRouter } from '@admin-bro/express' | ||
|
||
import AdminBro from 'admin-bro' | ||
import express from 'express' | ||
|
||
const PORT = 3000 | ||
|
||
export const listen = (admin: AdminBro, port = PORT) => { | ||
const router = buildRouter(admin) | ||
const app = express() | ||
|
||
app.use(admin.options.rootPath, router) | ||
|
||
|
||
app.use((error, req, res, next) => { | ||
if (error) { | ||
console.error(error) | ||
} | ||
next(error) | ||
}) | ||
|
||
app.listen(PORT, () => console.log('app is listening on http://localhost:3000/admin')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"outDir": "./build", | ||
"target": "es2017", | ||
"esModuleInterop": true, | ||
"jsx": "react", | ||
"strictNullChecks": true, | ||
"strictPropertyInitialization": false, | ||
"strictFunctionTypes": true, | ||
"strictBindCallApply": true, | ||
"noImplicitThis": true, | ||
"moduleResolution": "node", | ||
"module": "commonjs", | ||
"rootDir": "./", | ||
"types": ["cypress"], | ||
"paths": { | ||
"react": ["node_modules/@types/react"], | ||
"admin-bro": ["node_modules/admin-bro"], | ||
}, | ||
"baseUrl": "." | ||
}, | ||
"include": ["./src/**/*"] | ||
} |
Oops, something went wrong.