mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
Restore the userCreated event
This commit is contained in:
@@ -11,7 +11,9 @@ describe('graph.mutations.changeUsername', () => {
|
||||
let user;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
const ctx = Context.forSystem();
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'test@test.com',
|
||||
'testpassword1!',
|
||||
'kirk'
|
||||
|
||||
@@ -16,8 +16,10 @@ describe('graph.mutations.editComment', () => {
|
||||
beforeEach(async () => {
|
||||
timekeeper.reset();
|
||||
await SettingsService.init();
|
||||
const ctx = Context.forSystem();
|
||||
asset = await AssetModel.create({});
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
@@ -124,7 +126,9 @@ describe('graph.mutations.editComment', () => {
|
||||
body: `hello there! ${String(Math.random()).slice(2)}`,
|
||||
});
|
||||
|
||||
const ctx = Context.forSystem();
|
||||
const userB = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameB@example.com',
|
||||
'password',
|
||||
'usernameB'
|
||||
|
||||
@@ -34,12 +34,15 @@ describe('graph.mutations.ignoreUser', () => {
|
||||
});
|
||||
|
||||
it('users can ignoreUser', async () => {
|
||||
const ctx = Context.forSystem();
|
||||
let currentUser = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
);
|
||||
const userToIgnore = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameB@example.com',
|
||||
'password',
|
||||
'usernameB'
|
||||
@@ -83,7 +86,9 @@ describe('graph.mutations.ignoreUser', () => {
|
||||
});
|
||||
|
||||
it('users cannot ignore themselves', async () => {
|
||||
const ctx = Context.forSystem();
|
||||
const user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
@@ -124,18 +129,22 @@ describe('graph.mutations.stopIgnoringUser', () => {
|
||||
// We're going to ignore 2 users,
|
||||
// then stopIgnoring 1 of them
|
||||
// then assert myIgnoredUsers only lists the one remaining
|
||||
const ctx = Context.forSystem();
|
||||
let currentUser = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
);
|
||||
const usersToIgnore = await Promise.all([
|
||||
UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameB@example.com',
|
||||
'password',
|
||||
'usernameB'
|
||||
),
|
||||
UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameC@example.com',
|
||||
'password',
|
||||
'usernameC'
|
||||
|
||||
@@ -17,7 +17,9 @@ describe('graph.mutations.banUser', () => {
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
|
||||
const ctx = Context.forSystem();
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
|
||||
@@ -19,7 +19,9 @@ describe('graph.mutations.suspendUser', () => {
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
|
||||
const ctx = Context.forSystem();
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
|
||||
@@ -19,7 +19,9 @@ const { expect } = chai;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
|
||||
const ctx = Context.forSystem();
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
|
||||
@@ -17,23 +17,28 @@ describe('graph.queries.asset', () => {
|
||||
{ id: '1', url: 'https://example.com/?id=1' },
|
||||
{ id: '2', url: 'https://example.com/?id=2' },
|
||||
]);
|
||||
users = await UsersService.createLocalUsers([
|
||||
{
|
||||
email: 'usernameA@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameA',
|
||||
},
|
||||
{
|
||||
email: 'usernameB@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameB',
|
||||
},
|
||||
{
|
||||
email: 'usernameC@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameC',
|
||||
},
|
||||
]);
|
||||
const ctx = Context.forSystem();
|
||||
users = await Promise.all(
|
||||
[
|
||||
{
|
||||
email: 'usernameA@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameA',
|
||||
},
|
||||
{
|
||||
email: 'usernameB@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameB',
|
||||
},
|
||||
{
|
||||
email: 'usernameC@example.com',
|
||||
password: 'password',
|
||||
username: 'usernameC',
|
||||
},
|
||||
].map(({ email, username, password }) =>
|
||||
UsersService.createLocalUser(ctx, email, password, username)
|
||||
)
|
||||
);
|
||||
comments = await Promise.all(
|
||||
[0, 0, 1, 1].map(idx =>
|
||||
CommentsService.publicCreate({
|
||||
|
||||
@@ -14,8 +14,9 @@ describe('graph.queries.user', () => {
|
||||
let user;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
|
||||
const ctx = Context.forSystem();
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'usernameA@example.com',
|
||||
'password',
|
||||
'usernameA'
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
const app = require('../../../../../app');
|
||||
const Context = require('../../../../../graph/context');
|
||||
const UsersService = require('../../../../../services/users');
|
||||
|
||||
const chai = require('chai');
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
const expect = chai.expect;
|
||||
|
||||
const UsersService = require('../../../../../services/users');
|
||||
|
||||
describe('/api/v1/auth', () => {
|
||||
describe('#get', () => {
|
||||
it('should return nothing when no user is logged in', () => {
|
||||
@@ -32,7 +32,9 @@ describe('/api/v1/auth/local', () => {
|
||||
};
|
||||
await SettingsService.init(settings);
|
||||
|
||||
const ctx = Context.forSystem();
|
||||
mockUser = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'maria@gmail.com',
|
||||
'password!',
|
||||
'Maria'
|
||||
|
||||
@@ -3,6 +3,7 @@ const passport = require('../../../passport');
|
||||
const app = require('../../../../../app');
|
||||
const mailer = require('../../../../../services/mailer');
|
||||
|
||||
const Context = require('../../../../../graph/context');
|
||||
const SettingsService = require('../../../../../services/settings');
|
||||
const settings = {
|
||||
id: '1',
|
||||
@@ -20,19 +21,16 @@ const UsersService = require('../../../../../services/users');
|
||||
describe('/api/v1/users/:user_id/email/confirm', () => {
|
||||
let mockUser;
|
||||
|
||||
beforeEach(() =>
|
||||
SettingsService.init(settings)
|
||||
.then(() => {
|
||||
return UsersService.createLocalUser(
|
||||
'ana@gmail.com',
|
||||
'123321123',
|
||||
'Ana'
|
||||
);
|
||||
})
|
||||
.then(user => {
|
||||
mockUser = user;
|
||||
})
|
||||
);
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init(settings);
|
||||
const ctx = Context.forSystem();
|
||||
mockUser = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'ana@gmail.com',
|
||||
'123321123',
|
||||
'Ana'
|
||||
);
|
||||
});
|
||||
|
||||
describe('#post', () => {
|
||||
it('should send an email when we hit the endpoint', () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const CommentModel = require('../../../models/comment');
|
||||
const ActionModel = require('../../../models/action');
|
||||
|
||||
const UsersService = require('../../../services/users');
|
||||
const SettingsService = require('../../../services/settings');
|
||||
const CommentModel = require('../../../models/comment');
|
||||
const CommentsService = require('../../../services/comments');
|
||||
const Context = require('../../../graph/context');
|
||||
const SettingsService = require('../../../services/settings');
|
||||
const UsersService = require('../../../services/users');
|
||||
|
||||
const settings = {
|
||||
id: '1',
|
||||
@@ -119,9 +119,14 @@ describe('services.CommentsService', () => {
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init(settings);
|
||||
|
||||
const ctx = Context.forSystem();
|
||||
await Promise.all([
|
||||
CommentModel.create(comments),
|
||||
UsersService.createLocalUsers(users),
|
||||
Promise.all(
|
||||
users.map(({ email, password, username }) =>
|
||||
UsersService.createLocalUser(ctx, email, password, username)
|
||||
)
|
||||
),
|
||||
ActionModel.create(actions),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const TagsService = require('../../../services/tags');
|
||||
const UsersService = require('../../../services/users');
|
||||
const SettingsService = require('../../../services/settings');
|
||||
|
||||
const CommentModel = require('../../../models/comment');
|
||||
const Context = require('../../../graph/context');
|
||||
|
||||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
@@ -11,7 +11,9 @@ describe('services.TagsService', () => {
|
||||
let comment, user;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
const ctx = Context.forSystem();
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'stampi@gmail.com',
|
||||
'1Coral!!',
|
||||
'Stampi'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const TokensService = require('../../../services/tokens');
|
||||
const UsersService = require('../../../services/users');
|
||||
const SettingsService = require('../../../services/settings');
|
||||
const Context = require('../../../graph/context');
|
||||
|
||||
const chai = require('chai');
|
||||
chai.use(require('chai-as-promised'));
|
||||
@@ -10,7 +11,9 @@ describe('services.TokensService', () => {
|
||||
let user;
|
||||
beforeEach(async () => {
|
||||
await SettingsService.init();
|
||||
const ctx = Context.forSystem();
|
||||
user = await UsersService.createLocalUser(
|
||||
ctx,
|
||||
'sockmonster@gmail.com',
|
||||
'2Coral!!',
|
||||
'Sockmonster'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const UsersService = require('../../../services/users');
|
||||
const SettingsService = require('../../../services/settings');
|
||||
const mailer = require('../../../services/mailer');
|
||||
const Context = require('../../../graph/context');
|
||||
|
||||
const chai = require('chai');
|
||||
chai.use(require('chai-as-promised'));
|
||||
@@ -18,23 +19,28 @@ describe('services.UsersService', () => {
|
||||
};
|
||||
|
||||
await SettingsService.init(settings);
|
||||
mockUsers = await UsersService.createLocalUsers([
|
||||
{
|
||||
email: 'stampi@gmail.com',
|
||||
username: 'Stampi',
|
||||
password: '1Coral!-',
|
||||
},
|
||||
{
|
||||
email: 'sockmonster@gmail.com',
|
||||
username: 'Sockmonster',
|
||||
password: '2Coral!2',
|
||||
},
|
||||
{
|
||||
email: 'marvel@gmail.com',
|
||||
username: 'Marvel',
|
||||
password: '3Coral!3',
|
||||
},
|
||||
]);
|
||||
const ctx = Context.forSystem();
|
||||
mockUsers = await Promise.all(
|
||||
[
|
||||
{
|
||||
email: 'stampi@gmail.com',
|
||||
username: 'Stampi',
|
||||
password: '1Coral!-',
|
||||
},
|
||||
{
|
||||
email: 'sockmonster@gmail.com',
|
||||
username: 'Sockmonster',
|
||||
password: '2Coral!2',
|
||||
},
|
||||
{
|
||||
email: 'marvel@gmail.com',
|
||||
username: 'Marvel',
|
||||
password: '3Coral!3',
|
||||
},
|
||||
].map(({ email, username, password }) =>
|
||||
UsersService.createLocalUser(ctx, email, password, username)
|
||||
)
|
||||
);
|
||||
|
||||
sinon.spy(mailer, 'send');
|
||||
});
|
||||
@@ -89,19 +95,16 @@ describe('services.UsersService', () => {
|
||||
|
||||
describe('#createLocalUser', () => {
|
||||
it('should not create a user with duplicate username', () => {
|
||||
return UsersService.createLocalUsers([
|
||||
{
|
||||
email: 'otrostampi@gmail.com',
|
||||
username: 'StampiTheSecond',
|
||||
password: '1Coralito!',
|
||||
},
|
||||
])
|
||||
.then(user => {
|
||||
expect(user).to.be.null;
|
||||
})
|
||||
.catch(error => {
|
||||
expect(error).to.not.be.null;
|
||||
});
|
||||
const ctx = Context.forSystem();
|
||||
|
||||
return expect(
|
||||
UsersService.createLocalUser(
|
||||
ctx,
|
||||
'otrostampi@gmail.com',
|
||||
'1Coralito!',
|
||||
'Stampi'
|
||||
)
|
||||
).be.rejected;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user