You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
Server: Remove AccountOverLimit flag from accounts that are now below the limit
This commit is contained in:
@@ -20,7 +20,7 @@ describe('UserModel', function() {
|
||||
await beforeEachDb();
|
||||
});
|
||||
|
||||
test('should validate user objects', async function() {
|
||||
test('should validate user objects', async () => {
|
||||
const { user: user1 } = await createUserAndSession(2, false);
|
||||
const { user: user2 } = await createUserAndSession(3, false);
|
||||
|
||||
@@ -51,7 +51,7 @@ describe('UserModel', function() {
|
||||
expect(error instanceof ErrorUnprocessableEntity).toBe(true);
|
||||
});
|
||||
|
||||
test('should delete a user', async function() {
|
||||
test('should delete a user', async () => {
|
||||
const { session: session1, user: user1 } = await createUserAndSession(2, false);
|
||||
|
||||
const userModel = models().user();
|
||||
@@ -72,7 +72,7 @@ describe('UserModel', function() {
|
||||
expect((await models().userItem().all()).length).toBe(0);
|
||||
});
|
||||
|
||||
test('should push an email when creating a new user', async function() {
|
||||
test('should push an email when creating a new user', async () => {
|
||||
const { user: user1 } = await createUserAndSession(1);
|
||||
const { user: user2 } = await createUserAndSession(2);
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('UserModel', function() {
|
||||
expect(email.error).toBe('');
|
||||
});
|
||||
|
||||
test('should send a beta reminder email', async function() {
|
||||
test('should send a beta reminder email', async () => {
|
||||
stripeConfig().enabled = true;
|
||||
const { user: user1 } = await createUserAndSession(1, false, { email: 'toto@example.com' });
|
||||
const range = betaUserDateRange();
|
||||
@@ -140,7 +140,7 @@ describe('UserModel', function() {
|
||||
stripeConfig().enabled = false;
|
||||
});
|
||||
|
||||
test('should disable beta account once expired', async function() {
|
||||
test('should disable beta account once expired', async () => {
|
||||
stripeConfig().enabled = true;
|
||||
const { user: user1 } = await createUserAndSession(1, false, { email: 'toto@example.com' });
|
||||
const range = betaUserDateRange();
|
||||
@@ -166,7 +166,7 @@ describe('UserModel', function() {
|
||||
stripeConfig().enabled = false;
|
||||
});
|
||||
|
||||
test('should disable upload and send an email if payment failed recently', async function() {
|
||||
test('should disable upload and send an email if payment failed recently', async () => {
|
||||
stripeConfig().enabled = true;
|
||||
|
||||
const { user: user1 } = await models().subscription().saveUserAndSubscription('toto@example.com', 'Toto', AccountType.Basic, 'usr_111', 'sub_111');
|
||||
@@ -207,7 +207,7 @@ describe('UserModel', function() {
|
||||
stripeConfig().enabled = false;
|
||||
});
|
||||
|
||||
test('should disable disable the account and send an email if payment failed for good', async function() {
|
||||
test('should disable disable the account and send an email if payment failed for good', async () => {
|
||||
stripeConfig().enabled = true;
|
||||
|
||||
const { user: user1 } = await models().subscription().saveUserAndSubscription('toto@example.com', 'Toto', AccountType.Basic, 'usr_111', 'sub_111');
|
||||
@@ -236,7 +236,7 @@ describe('UserModel', function() {
|
||||
stripeConfig().enabled = false;
|
||||
});
|
||||
|
||||
test('should send emails when the account is over the size limit', async function() {
|
||||
test('should send emails and flag accounts when it is over the size limit', async () => {
|
||||
const { user: user1 } = await createUserAndSession(1);
|
||||
const { user: user2 } = await createUserAndSession(2);
|
||||
|
||||
@@ -287,6 +287,7 @@ describe('UserModel', function() {
|
||||
|
||||
// User upload should be disabled
|
||||
expect((await models().user().load(user2.id)).can_upload).toBe(0);
|
||||
expect(await models().userFlag().byUserId(user2.id, UserFlagType.AccountOverLimit)).toBeTruthy();
|
||||
|
||||
expect(emailAfterCount).toBe(emailBeforeCount + 1);
|
||||
const email = (await models().email().all()).pop();
|
||||
@@ -300,4 +301,25 @@ describe('UserModel', function() {
|
||||
}
|
||||
});
|
||||
|
||||
test('should remove flag when account goes under the limit', async () => {
|
||||
const { user: user1 } = await createUserAndSession(1);
|
||||
|
||||
await models().user().save({
|
||||
id: user1.id,
|
||||
account_type: AccountType.Basic,
|
||||
total_item_size: Math.round(accountByType(AccountType.Basic).max_total_item_size * 1.1),
|
||||
});
|
||||
|
||||
await models().user().handleOversizedAccounts();
|
||||
expect(await models().userFlag().byUserId(user1.id, UserFlagType.AccountOverLimit)).toBeTruthy();
|
||||
|
||||
await models().user().save({
|
||||
id: user1.id,
|
||||
total_item_size: Math.round(accountByType(AccountType.Basic).max_total_item_size * 0.5),
|
||||
});
|
||||
|
||||
await models().user().handleOversizedAccounts();
|
||||
expect(await models().userFlag().byUserId(user1.id, UserFlagType.AccountOverLimit)).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user