Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add customizable log level for 'username already exists' error #9336

Open
wants to merge 23 commits into
base: alpha
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c3e9106
feat: Add customizable log level for 'username already exists' error
KrishDave1 Oct 10, 2024
a54e2c6
feat: Made the suggested changes
KrishDave1 Oct 11, 2024
ae26647
fix: Added 2 log levels for Testing and followed new ParseServerConfi…
KrishDave1 Oct 12, 2024
8db9580
Merge branch 'alpha' into feat-branch
mtrezza Oct 12, 2024
da1785c
fix: Added a loop in test to remove redundant code
KrishDave1 Oct 12, 2024
1bedc3c
Merge branch 'feat-branch' of https://github.com/KrishDave1/parse-ser…
KrishDave1 Oct 12, 2024
63b4f9b
feat: Added the both the tests inside one testcase
KrishDave1 Oct 12, 2024
d582e56
Simplified the code further
KrishDave1 Oct 12, 2024
6c21038
refactor
mtrezza Oct 13, 2024
a557e78
consider default level
mtrezza Oct 13, 2024
0a5aa42
fix typo
mtrezza Oct 13, 2024
f537c2c
add warnjs
mtrezza Oct 13, 2024
8e4ac7c
Merge branch 'alpha' into feat-branch
mtrezza Oct 13, 2024
5ec7c82
Removed the extra logger from RestWrite.js
KrishDave1 Oct 15, 2024
a14f5f2
Merge branch 'alpha' into feat-branch
mtrezza Oct 15, 2024
386d2c1
fix: Usernames will always be unique for testing
KrishDave1 Oct 16, 2024
f028be7
Merge branch 'feat-branch' of https://github.com/KrishDave1/parse-ser…
KrishDave1 Oct 16, 2024
dff8140
Merge branch 'alpha' into feat-branch
mtrezza Oct 16, 2024
3587fb8
un-fdescribe
mtrezza Oct 16, 2024
9f3c82a
fit
mtrezza Oct 16, 2024
f1bc586
refactor
mtrezza Oct 16, 2024
2a03838
Check again for info
KrishDave1 Oct 16, 2024
3451ebf
Merge branch 'alpha' into feat-branch
mtrezza Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 31 additions & 45 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4447,55 +4447,41 @@ describe('custom log levels for username already exists error', () => {
infoSpy.calls.reset();
});

it('should respect warn log level for username already exists error', async () => {
await reconfigureServer({
logLevels: {
usernameAlreadyExists: 'warn',
},
});
const testCases = [
{ logLevel: 'warn', expectedSpy: 'warnSpy' },
{ logLevel: 'info', expectedSpy: 'infoSpy' },
];

testCases.forEach(({ logLevel, expectedSpy }) => {
it(`should respect ${logLevel} log level for username already exists error`, async () => {
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
await reconfigureServer({
logLevels: {
usernameAlreadyExists: logLevel,
},
});

const user = new Parse.User();
user.setUsername('existingUser');
user.setPassword('password');
await user.signUp();
const username = `existingUser_${logLevel}`;
mtrezza marked this conversation as resolved.
Show resolved Hide resolved

const duplicateUser = new Parse.User();
duplicateUser.setUsername('existingUser');
duplicateUser.setPassword('password');
const user = new Parse.User();
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
user.setUsername(username);
user.setPassword('password');
await user.signUp();

try {
await duplicateUser.signUp();
} catch (error) {
expect(error.code).toBe(Parse.Error.USERNAME_TAKEN);
expect(warnSpy).toHaveBeenCalled();
expect(errorSpy).not.toHaveBeenCalled();
expect(infoSpy).not.toHaveBeenCalled();
}
});
const duplicateUser = new Parse.User();
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
duplicateUser.setUsername(username);
duplicateUser.setPassword('password');

it('should respect info log level for username already exists error', async () => {
await reconfigureServer({
logLevels: {
usernameAlreadyExists: 'info',
},
try {
await duplicateUser.signUp();
} catch (error) {
expect(error.code).toBe(Parse.Error.USERNAME_TAKEN);
expect(this[expectedSpy]).toHaveBeenCalled();
['warnSpy', 'errorSpy', 'infoSpy'].forEach(spy => {
if (spy !== expectedSpy) {
expect(this[spy]).not.toHaveBeenCalled();
}
});
}
});

const user = new Parse.User();
user.setUsername('anotherExistingUser');
user.setPassword('password');
await user.signUp();

const duplicateUser = new Parse.User();
duplicateUser.setUsername('anotherExistingUser');
duplicateUser.setPassword('password');

try {
await duplicateUser.signUp();
} catch (error) {
expect(error.code).toBe(Parse.Error.USERNAME_TAKEN);
expect(infoSpy).toHaveBeenCalled();
expect(warnSpy).not.toHaveBeenCalled();
expect(errorSpy).not.toHaveBeenCalled();
}
});
});