Skip to content

Commit

Permalink
fix: ignore update password if already exists
Browse files Browse the repository at this point in the history
- chore: update test docs
  • Loading branch information
yxuo committed Jan 30, 2024
1 parent 2ffc8c2 commit e047786
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 100 deletions.
12 changes: 6 additions & 6 deletions src/auth-licensee/auth-licensee.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import { UsersService } from 'src/users/users.service';
import { BaseValidator } from 'src/utils/validators/base-validator';
import { AuthLicenseeService } from './auth-licensee.service';

/**
* All tests below were based on the requirements on GitHub.
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Requirements #94 - GitHub}
*/
describe('AuthLicenseeService', () => {
let authLicenseeService: AuthLicenseeService;
let jwtService: JwtService;
Expand Down Expand Up @@ -98,7 +94,9 @@ describe('AuthLicenseeService', () => {
});

describe('getInviteProfile', () => {
it('should throw exception when mail status is not SENT', async () => {
it('should throw exception when mail status is not SENT', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 18 - GitHub}
*/ async () => {
// Arrange
const user = new User({
id: 1,
Expand All @@ -124,7 +122,9 @@ describe('AuthLicenseeService', () => {
});

describe('concludeRegistration', () => {
it('should set mail status to SENT when succeeded', async () => {
it('should set mail status to SENT when succeeded', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 19 - GitHub}
*/ async () => {
// Arrange
const dateNow = new Date('2023-01-01T10:00:00');
const user = new User({
Expand Down
30 changes: 16 additions & 14 deletions src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import { InviteStatus } from 'src/mail-history-statuses/entities/mail-history-st

process.env.TZ = 'UTC';

/**
* All tests below were based on the requirements on GitHub.
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Requirements #94 - GitHub}
*/
describe('AuthService', () => {
let authService: AuthService;
let usersService: UsersService;
Expand Down Expand Up @@ -92,7 +88,9 @@ describe('AuthService', () => {
});

describe('resendRegisterMail', () => {
it('should throw exception when no mail quota available', async () => {
it('should throw exception when no mail quota available', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 13 - GitHub}
*/ async () => {
// Arrange
const user = new User({
id: 1,
Expand All @@ -111,11 +109,12 @@ describe('AuthService', () => {
await expect(response).rejects.toThrowError();
});

/**
xit('[FIXME] should throw exception when mail status is not QUEUED', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 15 - GitHub}
*
* FIXME: check if this requirement is still necessary
* error: received undefined instead of throw error
*/
xit('[FIXME] should throw exception when mail status is not QUEUED', async () => {
*/ async () => {
// Arrange
const user = new User({
id: 1,
Expand Down Expand Up @@ -146,10 +145,9 @@ describe('AuthService', () => {
);
});

/**
*@see {@link https://github.com/RJ-SMTR/api-cct/issues/164 Requirements #164 - GitHub}
*/
it('should return success regardless of quota status', async () => {
it('should return success regardless of quota status', /**
* Requirement: 2023/12/28 {@link https://github.com/RJ-SMTR/api-cct/issues/164 #164 - GitHub}
*/ async () => {
// Arrange
const users = [
new User({ id: 1, email: 'user1@mail.com', hash: 'hash_1' }),
Expand Down Expand Up @@ -206,7 +204,9 @@ describe('AuthService', () => {
});

describe('forgotPassword', () => {
it('should throw exception when no mail quota available', async () => {
it('should throw exception when no mail quota available', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 16 - GitHub}
*/ async () => {
// Arrange
jest.spyOn(mailHistoryService, 'getRemainingQuota').mockResolvedValue(0);

Expand All @@ -217,7 +217,9 @@ describe('AuthService', () => {
await expect(responsePromise).rejects.toThrowError();
});

it('should not consume the quota when available', async () => {
it('should not consume the quota when available', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 17 - GitHub}
*/ async () => {
// Arrange
const user = new User({ id: 1, email: 'user1@mail.com', hash: 'hash_1' });
const mailSentInfo = {
Expand Down
15 changes: 5 additions & 10 deletions src/bank-statements/bank-statements.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ describe('BankStatementsService', () => {

describe('getBankStatementsFromUser', () => {
it('should filter last 2 weeks', /**
* Requirements:
* - 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 1 - GitHub}
* Requirement: 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 1 - GitHub}
*
* Mocked today: 2023/01/22
*
Expand Down Expand Up @@ -215,8 +214,7 @@ describe('BankStatementsService', () => {
});

it('should filter last week', /**
* Requirements:
* - 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 2 - GitHub}
* Requirement: 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 2 - GitHub}
*
* Mocked today: 2023/01/22
*
Expand Down Expand Up @@ -356,8 +354,7 @@ describe('BankStatementsService', () => {
});

it('should filter last month', /**
* Requirements:
* - 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 3 - GitHub}
* Requirement: 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 3 - GitHub}
*
* Mocked today: 2023/01/17
*
Expand Down Expand Up @@ -515,8 +512,7 @@ describe('BankStatementsService', () => {
});

it('should throw exception when filtering by start-end dates', /**
* Requirements:
* - 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 4 - GitHub}
* Requirement: 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 4 - GitHub}
*/ async () => {
// Arrange
const bankStatements = allBankStatements.filter(
Expand All @@ -543,8 +539,7 @@ describe('BankStatementsService', () => {
});

it('should throw exception when profile is not found', /**
* Requirements:
* - 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 5 - GitHub}
* Requirement: 2024/01/18 {@link https://github.com/RJ-SMTR/api-cct/issues/168#issuecomment-1898457310 #168, item 5 - GitHub}
*/ async () => {
// Arrange
jest.spyOn(usersService, 'getOne').mockRejectedValue(new Error());
Expand Down
11 changes: 6 additions & 5 deletions src/cron-jobs/cron-jobs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import { MailRegistrationInterface } from 'src/mail/interfaces/mail-registration
import { DeepPartial } from 'typeorm';

/**
* All tests below were based on the requirements on GitHub.
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Requirements #94 - GitHub}
*
* FIXME: 'imports: [ < the Module containing BankRepository > ]'
*/
xdescribe('CronJobsService', () => {
Expand Down Expand Up @@ -96,7 +93,9 @@ xdescribe('CronJobsService', () => {
});

describe('bulkSendInvites', () => {
xit('[FIXME] should abort if no mail quota available', async () => {
xit('[FIXME] should abort if no mail quota available', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 11 - GitHub}
*/ async () => {
// Arrange
jest
.spyOn(settingsService, 'findOneBySettingData')
Expand All @@ -118,7 +117,9 @@ xdescribe('CronJobsService', () => {
expect(mailService.sendConcludeRegistration).toBeCalledTimes(0);
});

xit('[FIXME] should set mail status to SENT when succeeded', async () => {
xit('[FIXME] should set mail status to SENT when succeeded', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 12 - GitHub}
*/ async () => {
// Arrange
const dateNow = new Date('2023-01-01T10:00:00');
const user = new User({
Expand Down
2 changes: 1 addition & 1 deletion src/database/seeds/user/user-seed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class UserSeedService {
);
createdItem = (await this.userSeedRepository.findOne({
where: {
email: newItem.email as string,
email: item.email as string,
},
})) as User;
} else {
Expand Down
14 changes: 0 additions & 14 deletions src/mail-history/data/invite-mockup.ts

This file was deleted.

7 changes: 3 additions & 4 deletions src/mail-history/mail-history.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ describe('InviteService', () => {
expect(mailHistoryService).toBeDefined();
});

/**
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Requirements #94 - GitHub}
*/
describe('getUpdatedMailCounts', () => {
it('should return quota as max value after midnight', async () => {
it('should return quota as max value after midnight', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 10 - GitHub}
*/ async () => {
// Arrange
const findResult: Partial<MailHistory>[] = [
{
Expand Down
12 changes: 6 additions & 6 deletions src/ticket-revenues/ticket-revenues.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ describe('TicketRevenuesService', () => {
expect(ticketRevenuesService).toBeDefined();
});

// TODO: FIXME
/**
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/80#issuecomment-1806153475 Requirements - GitHub}
*/
describe('getMeGroupedFromUser', () => {
it('should return Gratuidade = R$ 0.00', async () => {
it('should return Gratuidade = R$ 0.00', /**
* Requirement: 2023/11/10 {@link https://github.com/RJ-SMTR/api-cct/issues/80#issuecomment-1806153475 #80, item 4 - GitHub}
*/ async () => {
// Arrange
const revenues: ITicketRevenue[] = [];
for (let day = 3; day >= 1; day--) {
Expand Down Expand Up @@ -145,7 +143,9 @@ describe('TicketRevenuesService', () => {
).toEqual(0);
});

it('should count and match transactionValueSum with sum of transactionType properties', async () => {
it('should count and match transactionValueSum with sum of transactionType properties', /**
* Requirement: 2023/11/10 {@link https://github.com/RJ-SMTR/api-cct/issues/80#issuecomment-1806153475 #80, item 6 - GitHub}
*/ async () => {
// Arrange
const revenues: ITicketRevenue[] = [];
for (let day = 3; day >= 1; day--) {
Expand Down
11 changes: 8 additions & 3 deletions src/users/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ export class User extends EntityHelper {
* @param userProps Properties to update
* @param removeConstraintKeys remove redundant keys to avoid database update
*/
update(userProps: DeepPartial<User>, removeUniqueKeys = false) {
update(userProps: DeepPartial<User>, asUpdateObject = false) {
const props = new User(userProps);
if (removeUniqueKeys && props?.email === this?.email) {
(props.email as any) = undefined;
if (asUpdateObject) {
if (props?.email === this?.email) {
(props.email as any) = undefined;
}
if (props?.password === undefined || props?.password === this.password) {
(props.password as any) = undefined;
}
}
Object.assign(this, props);
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/validators/is-not-number-string.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const IS_NUMBER_STRING = 'isNumberString';
* Checks if the string is non numeric.
* If given value is not a string, it also returns false.
*
* @forked {@link https://github.com/typestack/class-validator/blob/4639f93b9a95d04376b183bcbc0d14c42889c424/src/decorator/string/IsNumberString.ts IsNumberString.ts - class-validator}
* Forked from {@link https://github.com/typestack/class-validator/blob/4639f93b9a95d04376b183bcbc0d14c42889c424/src/decorator/string/IsNumberString.ts IsNumberString.ts - class-validator}
*/
export function isNotNumberString(
value: unknown,
Expand All @@ -21,7 +21,7 @@ export function isNotNumberString(
* Checks if the string is non numeric.
* If given value is not a string, it also returns false.
*
* @forked {@link https://github.com/typestack/class-validator/blob/4639f93b9a95d04376b183bcbc0d14c42889c424/src/decorator/string/IsNumberString.ts IsNumberString.ts - class-validator}
* Forked from {@link https://github.com/typestack/class-validator/blob/4639f93b9a95d04376b183bcbc0d14c42889c424/src/decorator/string/IsNumberString.ts IsNumberString.ts - class-validator}
*/
export function IsNotNumberString(
options?: ValidatorJS.IsNumericOptions,
Expand Down
7 changes: 3 additions & 4 deletions test/admin/auth.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ describe('Admin auth (e2e)', () => {
});
});

/**
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Phase 1, requirements #94 - GitHub}
*/
describe('Phase 1: Admin basics and user management', () => {
test('Login admin: POST /api/v1/auth/admin/email/login', () => {
return request(APP_URL)
Expand All @@ -37,7 +34,9 @@ describe('Admin auth (e2e)', () => {
});
});

test('Reset admin password', async () => {
test('Reset admin password', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 1 - GitHub}
*/ async () => {
await request(APP_URL)
.post('/api/v1/auth/forgot/password')
.send({
Expand Down
28 changes: 15 additions & 13 deletions test/admin/users.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ describe('Admin managing users (e2e)', () => {
});
});

/**
* Phase 1: manage users
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Requirements #94 - GitHub}
*/
describe('Manage users', () => {
test('Filter users', async () => {
test('Filter users', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 7 - GitHub}
*/ async () => {
// Arrange
const licensee = await request(app)
.get('/api/v1/users/')
Expand Down Expand Up @@ -132,10 +130,6 @@ describe('Admin managing users (e2e)', () => {
}, 20000);
});

/**
* Phase 1: upload users
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Requirements #94 - GitHub}
*/
describe('Upload users', () => {
let uploadUsers: any[];
let users: any[] = [];
Expand All @@ -153,7 +147,9 @@ describe('Admin managing users (e2e)', () => {
];
});

test(`Upload users, status = 'queued'`, async () => {
test(`Upload users, status = 'queued'`, /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 3 - GitHub}
*/ async () => {
// Arrange
const excelFilePath = path.join(tempFolder, 'newUsers.xlsx');
const workbook = XLSX.utils.book_new();
Expand Down Expand Up @@ -189,7 +185,9 @@ describe('Admin managing users (e2e)', () => {
.then(({ body }) => body.data);
});

test(`Resend new user invite, status = 'sent'`, async () => {
test(`Resend new user invite, status = 'sent'`, /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 4 - GitHub}
*/ async () => {
const newUser = users[0];
expect(newUser?.id).toBeDefined();

Expand Down Expand Up @@ -234,7 +232,9 @@ describe('Admin managing users (e2e)', () => {
users[0] = newUser;
});

test(`New user conclude registration, status = 'used'`, async () => {
test(`New user conclude registration, status = 'used'`, /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 5 - GitHub}
*/ async () => {
const newUser = users[0];
expect(newUser?.hash).toBeDefined();

Expand All @@ -252,7 +252,9 @@ describe('Admin managing users (e2e)', () => {
users[0] = newUser;
});

test('New user login', async () => {
test('New user login', /**
* Requirement: 2023/11/16 {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 #94, item 6 - GitHub}
*/ async () => {
const newUser = users[0];
await request(APP_URL)
.post(`/api/v1/auth/licensee/login`)
Expand Down
Loading

0 comments on commit e047786

Please sign in to comment.