Skip to content

Commit 44843e3

Browse files
committed
add tests
1 parent b85ed20 commit 44843e3

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

spec/index.spec.js

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ describe('server', () => {
735735
).toBeRejected();
736736
});
737737

738-
it('should execute publicServerURL function on every access', async () => {
738+
it('executes publicServerURL function on every config access', async () => {
739739
let counter = 0;
740740
await reconfigureServer({
741741
publicServerURL: () => {
@@ -762,5 +762,94 @@ describe('server', () => {
762762
expect(config3.publicServerURL).toEqual('https://example.com/3');
763763
expect(counter).toEqual(3);
764764
});
765+
766+
it('executes publicServerURL function on every password reset email', async () => {
767+
let counter = 0;
768+
const emailCalls = [];
769+
770+
const emailAdapter = MockEmailAdapterWithOptions({
771+
sendPasswordResetEmail: ({ link }) => {
772+
emailCalls.push(link);
773+
return Promise.resolve();
774+
},
775+
});
776+
777+
await reconfigureServer({
778+
appName: 'test-app',
779+
publicServerURL: () => {
780+
counter++;
781+
return `https://example.com/${counter}`;
782+
},
783+
emailAdapter,
784+
});
785+
786+
// Create a user
787+
const user = new Parse.User();
788+
user.setUsername('user');
789+
user.setPassword('pass');
790+
user.setEmail('[email protected]');
791+
await user.signUp();
792+
793+
// Should use first publicServerURL
794+
const counterBefore1 = counter;
795+
await Parse.User.requestPasswordReset('[email protected]');
796+
await jasmine.timeout();
797+
expect(emailCalls.length).toEqual(1);
798+
expect(emailCalls[0]).toContain(`https://example.com/${counterBefore1 + 1}`);
799+
expect(counter).toBeGreaterThanOrEqual(2);
800+
801+
// Should use updated publicServerURL
802+
const counterBefore2 = counter;
803+
await Parse.User.requestPasswordReset('[email protected]');
804+
await jasmine.timeout();
805+
expect(emailCalls.length).toEqual(2);
806+
expect(emailCalls[1]).toContain(`https://example.com/${counterBefore2 + 1}`);
807+
expect(counterBefore2).toBeGreaterThan(counterBefore1);
808+
});
809+
810+
it('executes publicServerURL function on every verification email', async () => {
811+
let counter = 0;
812+
const emailCalls = [];
813+
814+
const emailAdapter = MockEmailAdapterWithOptions({
815+
sendVerificationEmail: ({ link }) => {
816+
emailCalls.push(link);
817+
return Promise.resolve();
818+
},
819+
});
820+
821+
await reconfigureServer({
822+
appName: 'test-app',
823+
verifyUserEmails: true,
824+
publicServerURL: () => {
825+
counter++;
826+
return `https://example.com/${counter}`;
827+
},
828+
emailAdapter,
829+
});
830+
831+
// Should trigger verification email with first publicServerURL
832+
const counterBefore1 = counter;
833+
const user1 = new Parse.User();
834+
user1.setUsername('user1');
835+
user1.setPassword('pass1');
836+
user1.setEmail('[email protected]');
837+
await user1.signUp();
838+
await jasmine.timeout();
839+
expect(emailCalls.length).toEqual(1);
840+
expect(emailCalls[0]).toContain(`https://example.com/${counterBefore1 + 1}`);
841+
842+
// Should trigger verification email with updated publicServerURL
843+
const counterBefore2 = counter;
844+
const user2 = new Parse.User();
845+
user2.setUsername('user2');
846+
user2.setPassword('pass2');
847+
user2.setEmail('[email protected]');
848+
await user2.signUp();
849+
await jasmine.timeout();
850+
expect(emailCalls.length).toEqual(2);
851+
expect(emailCalls[1]).toContain(`https://example.com/${counterBefore2 + 1}`);
852+
expect(counterBefore2).toBeGreaterThan(counterBefore1);
853+
});
765854
});
766855
});

0 commit comments

Comments
 (0)