Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class AppController {
subControllers = [
MyController,
AuthController
];
}
await createConnection({
database: 'e2e_db.sqlite',
dropSchema: true,
entities: [ User, Permission, Group ],
synchronize: true,
type: 'sqlite',
});
const app = createApp(AppController);
/* Create a user */
await createConnection({
database: 'e2e_db.sqlite',
dropSchema: true,
entities: [ User, Permission, Group ],
name: 'create-connection',
synchronize: true,
type: 'sqlite',
});
const user = new User();
user.email = 'john@foalts.org';
user.password = await hashPassword('password');
await getRepository(User, 'create-connection').save(user);
text: string;
}
class SocialPostController {
@Post()
@ValidateBodyFromClass(SocialPost, { /* options if relevant */ })
createSocialPost() {
// ...
return new HttpResponseCreated();
}
}
const app = createApp(SocialPostController);
return request(app)
.post('/')
.send({ text: 'foo' })
.expect(400)
.expect([
{
children: [],
constraints: { length: 'title must be longer than or equal to 10 characters' },
property: 'title',
target: { text: 'foo' },
},
{
children: [],
constraints: { contains: 'text must contain a hello string' },
property: 'text',
async function main() {
// Init Nuxt.js
const nuxt = new Nuxt(config);
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt);
await builder.build();
} else {
await nuxt.ready();
}
await createConnection();
const app = createApp(AppController, {
postMiddlewares: [
nuxt.render
]
});
const httpServer = http.createServer(app);
const port = Config.get('port', 3001);
httpServer.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
}
class AuthController extends LoginController {
strategies = [
strategy('login', Authenticator, {})
];
}
class AppController {
subControllers = [
controller('/users', UserController),
controller('/orgs', OrgController),
controller('', AuthController),
];
}
const app = createApp(AppController);
/* Create orgs, perms, groups and users */
await createConnection({
database: 'e2e_db.sqlite',
dropSchema: true,
entities: [ User, Permission, Group, Org ],
name: 'create-connection',
synchronize: true,
type: 'sqlite',
});
const adminPerm = new Permission();
adminPerm.name = 'Admin permission';
adminPerm.codeName = 'admin-perm';
before(async () => {
process.env.SETTINGS_SESSION_SECRET = 'session-secret';
await createConnection({
database: 'e2e_db.sqlite',
dropSchema: true,
entities: [ User ],
synchronize: true,
type: 'sqlite',
});
app = createApp(AppController);
});
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group).save(group);
user1.userPermissions = [ perm ];
user2.groups = [ group ];
await getRepository(User).save([ user1, user2 ]);
const session1 = await createService(TypeORMStore).createAndSaveSessionFromUser(user1);
tokenUser1 = session1.getToken();
const session2 = await createService(TypeORMStore).createAndSaveSessionFromUser(user2);
tokenUser2 = session2.getToken();
app = createApp(AppController);
});
await new Promise((resolve, reject) => {
redisClient.flushdb((err, success) => {
if (err) {
return reject(err);
}
resolve(success);
});
});
const user = new UserModel();
user.email = 'john@foalts.org';
user.password = await hashPassword('password');
user.isAdmin = false;
await user.save();
app = createApp(AppController);
});
await new Promise((resolve, reject) => {
redisClient.flushdb((err, success) => {
if (err) {
return reject(err);
}
resolve(success);
});
});
const user = new UserModel();
user.email = 'john@foalts.org';
user.password = await hashPassword('password');
user.isAdmin = false;
await user.save();
app = createApp(AppController);
});
it('should send a request with the access token and return the response body.', async () => {
const userInfo = { email: 'john@foalts.org' };
class AppController {
@Get('/users/me')
token(ctx: Context) {
const { authorization } = ctx.request.headers;
strictEqual(authorization, 'token an_access_token');
return new HttpResponseOK(userInfo);
}
}
server = createApp(AppController).listen(3000);
const tokens: SocialTokens = {
access_token: 'an_access_token',
token_type: 'token_type'
};
const actual = await provider.getUserInfoFromTokens(tokens);
deepStrictEqual(actual, userInfo);
});
async function main() {
await createConnection(require('../ormconfig.json'));
const app = createApp(AppController);
const httpServer = http.createServer(app);
const port = Config.get('port', 3001);
httpServer.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
}