From 2a47c1e38956b2fedc48af47b3b7dc0541773451 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Sat, 28 Dec 2024 00:08:04 +0500 Subject: [PATCH 01/11] feat: add session_id to request headers --- src/store/main.ts | 247 +++++++++++++++++++++++++++++++--------------- 1 file changed, 165 insertions(+), 82 deletions(-) diff --git a/src/store/main.ts b/src/store/main.ts index f73884da..f671401b 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -218,7 +218,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -334,7 +335,8 @@ export class MainStore { const headers = { 'x-jwt': info.jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }; try { @@ -425,7 +427,8 @@ export class MainStore { async postToCache(payload: any): Promise { await api.post('save', payload, { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }); return; } @@ -764,7 +767,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -840,7 +844,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -1490,6 +1495,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', + session_id: this.sessionId, Accept: 'application/json' } }); @@ -1650,7 +1656,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -1670,7 +1677,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -1707,7 +1715,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info?.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -1738,7 +1747,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info?.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); if (response.status) { @@ -1775,7 +1785,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -1796,7 +1807,8 @@ export class MainStore { }), headers: { 'x-jwt': info.jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -1886,7 +1898,8 @@ export class MainStore { }), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2066,7 +2079,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2164,7 +2178,8 @@ export class MainStore { route_hint: body.route_hint }, { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } ); return data; @@ -2190,7 +2205,8 @@ export class MainStore { payment_type: body.payment_type }, { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } ); return data; @@ -2214,7 +2230,8 @@ export class MainStore { }), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2248,7 +2265,8 @@ export class MainStore { method: 'GET', mode: 'cors', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2270,7 +2288,8 @@ export class MainStore { method: 'GET', mode: 'cors', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2289,7 +2308,8 @@ export class MainStore { method: 'GET', mode: 'cors', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2313,7 +2333,8 @@ export class MainStore { }), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2357,7 +2378,8 @@ export class MainStore { }), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2405,7 +2427,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2426,7 +2449,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2453,7 +2477,8 @@ export class MainStore { }), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2476,7 +2501,8 @@ export class MainStore { }), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2503,7 +2529,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2526,7 +2553,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2547,7 +2575,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2567,7 +2596,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2587,7 +2617,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2607,7 +2638,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2628,7 +2660,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2649,7 +2682,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2673,7 +2707,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2695,7 +2730,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } } ); @@ -2717,7 +2753,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2734,7 +2771,8 @@ export class MainStore { method: 'GET', mode: 'cors', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2756,7 +2794,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2772,7 +2811,8 @@ export class MainStore { method: 'GET', mode: 'cors', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2805,7 +2845,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2828,7 +2869,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2848,7 +2890,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r.json(); @@ -2867,7 +2910,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r; @@ -2886,7 +2930,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); return r; @@ -2904,7 +2949,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2923,7 +2969,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2942,7 +2989,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2966,7 +3014,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -2991,7 +3040,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3015,7 +3065,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3034,7 +3085,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3054,7 +3106,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3074,7 +3127,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3094,7 +3148,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3118,7 +3173,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3139,7 +3195,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3176,7 +3233,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3197,7 +3255,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3218,7 +3277,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3247,7 +3307,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3285,7 +3346,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3324,7 +3386,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3364,7 +3427,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3399,7 +3463,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3432,7 +3497,8 @@ export class MainStore { body: JSON.stringify(body), headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3452,7 +3518,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3474,7 +3541,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); if (!response.ok) { @@ -3497,7 +3565,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }, body: JSON.stringify(repo) }); @@ -3524,7 +3593,8 @@ export class MainStore { const mode = 'cors'; const headers = { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }; const body = JSON.stringify(repo); @@ -3556,7 +3626,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } } ); @@ -3583,7 +3654,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); if (!response.ok) { @@ -3611,7 +3683,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3637,7 +3710,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } } ); @@ -3659,7 +3733,8 @@ export class MainStore { const mode = 'cors'; const headers = { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }; const body = JSON.stringify(phase); @@ -3686,7 +3761,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3718,7 +3794,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }, body: JSON.stringify(ticketPayload) }); @@ -3745,7 +3822,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }, body: JSON.stringify(payload) }); @@ -3772,7 +3850,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3818,7 +3897,8 @@ export class MainStore { body: body, headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3838,7 +3918,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } }); @@ -3862,7 +3943,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId }, body: JSON.stringify(codeGraph) }); @@ -3889,7 +3971,8 @@ export class MainStore { mode: 'cors', headers: { 'x-jwt': info.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: this.sessionId } } ); From dde3e2e649c5dc20691ffc59db275ba53395afad Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Sat, 28 Dec 2024 11:08:06 +0500 Subject: [PATCH 02/11] fix unit test --- src/bounties/__tests__/bountyTest.spec.ts | 29 ++++++++- src/store/__test__/main.spec.ts | 72 +++++++++++++++-------- 2 files changed, 74 insertions(+), 27 deletions(-) diff --git a/src/bounties/__tests__/bountyTest.spec.ts b/src/bounties/__tests__/bountyTest.spec.ts index f0067491..4f77da5f 100644 --- a/src/bounties/__tests__/bountyTest.spec.ts +++ b/src/bounties/__tests__/bountyTest.spec.ts @@ -17,6 +17,15 @@ const mockedApi = api as jest.Mocked; describe('Bounty Tests', () => { beforeAll(() => { Object.defineProperty(window, 'localStorage', { value: localStorageMock }); + const Crypto = { + getRandomValues: (arr: Uint8Array) => { + for (let i = 0; i < arr.length; i++) { + arr[i] = Math.floor(Math.random() * 256); + } + return arr; + } + }; + global.crypto = Crypto as any; }); beforeEach(() => { @@ -37,6 +46,10 @@ describe('Bounty Tests', () => { it('should save a new bounty and persist to localStorage', async () => { global.fetch = jest.fn(); mockedApi.post = jest.fn().mockResolvedValue(newBounty); + + mainStore.initializeSessionId(); + const { sessionId } = mainStore; + await mainStore.saveBounty(newBounty); expect(mockedApi.post).toHaveBeenCalledTimes(0); expect(global.fetch).toHaveBeenCalledTimes(1); @@ -45,7 +58,11 @@ describe('Bounty Tests', () => { 'http://localhost:5002/gobounties?token=undefined', { body: JSON.stringify(newBounty), - headers: { 'Content-Type': 'application/json', 'x-jwt': undefined }, + headers: { + 'Content-Type': 'application/json', + 'x-jwt': undefined, + session_id: sessionId + }, method: 'POST', mode: 'cors' } @@ -68,11 +85,14 @@ describe('Bounty Tests', () => { mockedApi.del = jest.fn().mockResolvedValue({}); await mainStore.deleteBounty(bountyIdToDelete, publicKeyToDelete); + mainStore.initializeSessionId(); + const { sessionId } = mainStore; + const deleteRequestContent = [ 'http://localhost:5002/gobounties?token=undefined', { body: JSON.stringify(newBounty), - headers: { 'Content-Type': 'application/json', 'x-jwt': undefined }, + headers: { 'Content-Type': 'application/json', 'x-jwt': undefined, session_id: sessionId }, method: 'POST', mode: 'cors' } @@ -89,11 +109,14 @@ describe('Bounty Tests', () => { it('should fetch and persist people bounties to localStorage', async () => { await mainStore.getPeopleBounties(); + mainStore.initializeSessionId(); + const { sessionId } = mainStore; + const peopleRequestContent = [ 'http://localhost:5002/gobounties?token=undefined', { body: JSON.stringify(newBounty), - headers: { 'Content-Type': 'application/json', 'x-jwt': undefined }, + headers: { 'Content-Type': 'application/json', 'x-jwt': undefined, session_id: sessionId }, method: 'POST', mode: 'cors' } diff --git a/src/store/__test__/main.spec.ts b/src/store/__test__/main.spec.ts index 77d30f3a..608f4ff7 100644 --- a/src/store/__test__/main.spec.ts +++ b/src/store/__test__/main.spec.ts @@ -18,6 +18,15 @@ let mockApiResponseData: any[]; const origFetch = global.fetch; +const Crypto = { + getRandomValues: (arr: Uint8Array) => { + for (let i = 0; i < arr.length; i++) { + arr[i] = Math.floor(Math.random() * 256); + } + return arr; + } +}; + beforeAll(() => { fetchStub = sinon.stub(global, 'fetch'); fetchStub.returns(Promise.resolve({ status: 200, json: () => Promise.resolve({}) })); // Mock a default behavior @@ -26,6 +35,7 @@ beforeAll(() => { { uuid: 'cldl1g04nncmf23du7kg' }, { orgUUID: 'cmas9gatu2rvqiev4ur0' } ]; + global.crypto = Crypto as any; }); afterAll(() => { @@ -548,19 +558,26 @@ describe('Main store', () => { it('should send request delete request with correct body and url', async () => { const url = `${TribesURL}/gobounties/pub_key/1111`; const allBountiesUrl = `http://${getHost()}/gobounties/all?limit=10&sortBy=created&search=&page=1&resetPage=true&Open=true&Assigned=false&Paid=false`; + + const store = new MainStore(); + store.initializeSessionId(); + const expectedRequestOptions: RequestInit = { method: 'DELETE', mode: 'cors', headers: { 'x-jwt': user.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: store.sessionId } }; + fetchStub.withArgs(url, expectedRequestOptions).returns( Promise.resolve({ status: 200 }) as any ); + fetchStub.withArgs(allBountiesUrl, sinon.match.any).returns( Promise.resolve({ status: 200, @@ -569,7 +586,6 @@ describe('Main store', () => { }) as any ); - const store = new MainStore(); await store.deleteBounty(1111, 'pub_key'); expect(fetchStub.withArgs(url, expectedRequestOptions).calledOnce).toEqual(true); @@ -579,17 +595,21 @@ describe('Main store', () => { it('should not panic if failed to delete bounty', async () => { const url = `${TribesURL}/gobounties/pub_key/1111`; + + const store = new MainStore(); + store.initializeSessionId(); + const expectedRequestOptions: RequestInit = { method: 'DELETE', mode: 'cors', headers: { 'x-jwt': user.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).throwsException(); - const store = new MainStore(); await store.deleteBounty(1111, 'pub_key'); expect(fetchStub.withArgs(url, expectedRequestOptions).calledOnce).toEqual(true); @@ -598,6 +618,10 @@ describe('Main store', () => { it('should not return false if asignee removed successfully', async () => { const url = `${TribesURL}/gobounties/assignee`; + + const store = new MainStore(); + store.initializeSessionId(); + const expectedRequestOptions: RequestInit = { method: 'DELETE', mode: 'cors', @@ -607,7 +631,8 @@ describe('Main store', () => { }), headers: { 'x-jwt': user.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).returns( @@ -616,7 +641,6 @@ describe('Main store', () => { }) as any ); - const store = new MainStore(); const res = await store.deleteBountyAssignee({ owner_pubkey: 'pub_key', created: '1111' }); expect(fetchStub.withArgs(url, expectedRequestOptions).calledOnce).toEqual(true); @@ -625,6 +649,10 @@ describe('Main store', () => { it('should return false if failed to remove asignee ', async () => { const url = `${TribesURL}/gobounties/assignee`; + + const store = new MainStore(); + store.initializeSessionId(); + const expectedRequestOptions: RequestInit = { method: 'DELETE', mode: 'cors', @@ -634,12 +662,12 @@ describe('Main store', () => { }), headers: { 'x-jwt': user.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).throwsException(); - const store = new MainStore(); const res = await store.deleteBountyAssignee({ owner_pubkey: 'pub_key', created: '1111' }); expect(fetchStub.withArgs(url, expectedRequestOptions).calledOnce).toEqual(true); @@ -648,12 +676,17 @@ describe('Main store', () => { it('should successfully update bounty payment status', async () => { const url = `${TribesURL}/gobounties/paymentstatus/1111`; + + const store = new MainStore(); + store.initializeSessionId(); + const expectedRequestOptions: RequestInit = { method: 'POST', mode: 'cors', headers: { 'x-jwt': user.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).returns( @@ -662,7 +695,6 @@ describe('Main store', () => { }) as any ); - const store = new MainStore(); const res = await store.updateBountyPaymentStatus(1111); expect(fetchStub.withArgs(url, expectedRequestOptions).calledOnce).toEqual(true); @@ -671,17 +703,21 @@ describe('Main store', () => { it('should return false if failed to update bounty status', async () => { const url = `${TribesURL}/gobounties/paymentstatus/1111`; + + const store = new MainStore(); + store.initializeSessionId(); + const expectedRequestOptions: RequestInit = { method: 'POST', mode: 'cors', headers: { 'x-jwt': user.tribe_jwt, - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + session_id: store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).throwsException(); - const store = new MainStore(); const res = await store.updateBountyPaymentStatus(1111); expect(fetchStub.withArgs(url, expectedRequestOptions).calledOnce).toEqual(true); @@ -758,18 +794,6 @@ describe('Main store', () => { // Arrange: Set user as logged out uiStore.setMeInfo(emptyMeInfo); - // Define the expected query parameters - const queryParams = new URLSearchParams({ - limit: '10', - sortBy: 'updatedat', - search: 'random', - page: '1', - resetPage: 'true' - // Add languages if applicable, e.g., languages: 'javascript,typescript' - }); - - const allBountiesUrl = `http://${getHost()}/gobounties/all?${queryParams.toString()}`; - // Stub the fetch with a flexible matcher fetchStub .withArgs( From a4e2119594e19cfdcc38711e246dad551525181f Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Mon, 30 Dec 2024 21:21:59 +0500 Subject: [PATCH 03/11] fix session id --- src/store/main.ts | 166 +++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/store/main.ts b/src/store/main.ts index f671401b..4854a977 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -219,7 +219,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -336,7 +336,7 @@ export class MainStore { const headers = { 'x-jwt': info.jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }; try { @@ -428,7 +428,7 @@ export class MainStore { async postToCache(payload: any): Promise { await api.post('save', payload, { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }); return; } @@ -768,7 +768,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -845,7 +845,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -1495,7 +1495,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId, + 'session_id': this.sessionId, Accept: 'application/json' } }); @@ -1657,7 +1657,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -1678,7 +1678,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -1716,7 +1716,7 @@ export class MainStore { headers: { 'x-jwt': info?.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -1748,7 +1748,7 @@ export class MainStore { headers: { 'x-jwt': info?.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); if (response.status) { @@ -1786,7 +1786,7 @@ export class MainStore { headers: { 'x-jwt': info.jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -1808,7 +1808,7 @@ export class MainStore { headers: { 'x-jwt': info.jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -1899,7 +1899,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2080,7 +2080,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2179,7 +2179,7 @@ export class MainStore { }, { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } ); return data; @@ -2206,7 +2206,7 @@ export class MainStore { }, { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } ); return data; @@ -2231,7 +2231,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2266,7 +2266,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2289,7 +2289,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2309,7 +2309,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2334,7 +2334,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2379,7 +2379,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2428,7 +2428,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2450,7 +2450,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2478,7 +2478,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2502,7 +2502,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2530,7 +2530,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2554,7 +2554,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2576,7 +2576,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2597,7 +2597,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2618,7 +2618,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2639,7 +2639,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2661,7 +2661,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2683,7 +2683,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2708,7 +2708,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2731,7 +2731,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } } ); @@ -2754,7 +2754,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2772,7 +2772,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2795,7 +2795,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2812,7 +2812,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2846,7 +2846,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2870,7 +2870,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2891,7 +2891,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r.json(); @@ -2911,7 +2911,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r; @@ -2931,7 +2931,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); return r; @@ -2950,7 +2950,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2970,7 +2970,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -2990,7 +2990,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3015,7 +3015,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3041,7 +3041,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3066,7 +3066,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3086,7 +3086,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3107,7 +3107,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3128,7 +3128,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3149,7 +3149,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3174,7 +3174,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3196,7 +3196,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3234,7 +3234,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3256,7 +3256,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3278,7 +3278,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3308,7 +3308,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3347,7 +3347,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3387,7 +3387,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3428,7 +3428,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3464,7 +3464,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3498,7 +3498,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3519,7 +3519,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3542,7 +3542,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); if (!response.ok) { @@ -3566,7 +3566,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }, body: JSON.stringify(repo) }); @@ -3594,7 +3594,7 @@ export class MainStore { const headers = { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }; const body = JSON.stringify(repo); @@ -3627,7 +3627,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } } ); @@ -3655,7 +3655,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); if (!response.ok) { @@ -3684,7 +3684,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3711,7 +3711,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } } ); @@ -3734,7 +3734,7 @@ export class MainStore { const headers = { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }; const body = JSON.stringify(phase); @@ -3762,7 +3762,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3795,7 +3795,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }, body: JSON.stringify(ticketPayload) }); @@ -3823,7 +3823,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }, body: JSON.stringify(payload) }); @@ -3851,7 +3851,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3898,7 +3898,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3919,7 +3919,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } }); @@ -3944,7 +3944,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId }, body: JSON.stringify(codeGraph) }); @@ -3972,7 +3972,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - session_id: this.sessionId + 'session_id': this.sessionId } } ); From af11fa0478fab8bc6f58116a85f8a3e1a5397ab5 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Mon, 30 Dec 2024 22:45:16 +0500 Subject: [PATCH 04/11] change session id format and fix unit test --- src/bounties/__tests__/bountyTest.spec.ts | 14 +- src/store/__test__/main.spec.ts | 12 +- src/store/main.ts | 171 +++++++++++----------- 3 files changed, 103 insertions(+), 94 deletions(-) diff --git a/src/bounties/__tests__/bountyTest.spec.ts b/src/bounties/__tests__/bountyTest.spec.ts index 4f77da5f..eca66246 100644 --- a/src/bounties/__tests__/bountyTest.spec.ts +++ b/src/bounties/__tests__/bountyTest.spec.ts @@ -61,7 +61,7 @@ describe('Bounty Tests', () => { headers: { 'Content-Type': 'application/json', 'x-jwt': undefined, - session_id: sessionId + 'x-session-id': sessionId }, method: 'POST', mode: 'cors' @@ -92,7 +92,11 @@ describe('Bounty Tests', () => { 'http://localhost:5002/gobounties?token=undefined', { body: JSON.stringify(newBounty), - headers: { 'Content-Type': 'application/json', 'x-jwt': undefined, session_id: sessionId }, + headers: { + 'Content-Type': 'application/json', + 'x-jwt': undefined, + 'x-session-id': sessionId + }, method: 'POST', mode: 'cors' } @@ -116,7 +120,11 @@ describe('Bounty Tests', () => { 'http://localhost:5002/gobounties?token=undefined', { body: JSON.stringify(newBounty), - headers: { 'Content-Type': 'application/json', 'x-jwt': undefined, session_id: sessionId }, + headers: { + 'Content-Type': 'application/json', + 'x-jwt': undefined, + 'x-session-id': sessionId + }, method: 'POST', mode: 'cors' } diff --git a/src/store/__test__/main.spec.ts b/src/store/__test__/main.spec.ts index 608f4ff7..729268fa 100644 --- a/src/store/__test__/main.spec.ts +++ b/src/store/__test__/main.spec.ts @@ -568,7 +568,7 @@ describe('Main store', () => { headers: { 'x-jwt': user.tribe_jwt, 'Content-Type': 'application/json', - session_id: store.sessionId + 'x-session-id': store.sessionId } }; @@ -605,7 +605,7 @@ describe('Main store', () => { headers: { 'x-jwt': user.tribe_jwt, 'Content-Type': 'application/json', - session_id: store.sessionId + 'x-session-id': store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).throwsException(); @@ -632,7 +632,7 @@ describe('Main store', () => { headers: { 'x-jwt': user.tribe_jwt, 'Content-Type': 'application/json', - session_id: store.sessionId + 'x-session-id': store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).returns( @@ -663,7 +663,7 @@ describe('Main store', () => { headers: { 'x-jwt': user.tribe_jwt, 'Content-Type': 'application/json', - session_id: store.sessionId + 'x-session-id': store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).throwsException(); @@ -686,7 +686,7 @@ describe('Main store', () => { headers: { 'x-jwt': user.tribe_jwt, 'Content-Type': 'application/json', - session_id: store.sessionId + 'x-session-id': store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).returns( @@ -713,7 +713,7 @@ describe('Main store', () => { headers: { 'x-jwt': user.tribe_jwt, 'Content-Type': 'application/json', - session_id: store.sessionId + 'x-session-id': store.sessionId } }; fetchStub.withArgs(url, expectedRequestOptions).throwsException(); diff --git a/src/store/main.ts b/src/store/main.ts index 4854a977..7b057283 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -195,7 +195,8 @@ export class MainStore { headers: { 'x-jwt': info.jwt, 'Content-Type': 'application/json', - Accept: 'application/json' + Accept: 'application/json', + 'x-session-id': this.sessionId } }); @@ -219,7 +220,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -336,7 +337,7 @@ export class MainStore { const headers = { 'x-jwt': info.jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }; try { @@ -428,7 +429,7 @@ export class MainStore { async postToCache(payload: any): Promise { await api.post('save', payload, { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }); return; } @@ -768,7 +769,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -845,7 +846,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -1495,8 +1496,8 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId, - Accept: 'application/json' + Accept: 'application/json', + 'x-session-id': this.sessionId } }); @@ -1657,7 +1658,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -1678,7 +1679,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -1716,7 +1717,7 @@ export class MainStore { headers: { 'x-jwt': info?.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -1748,7 +1749,7 @@ export class MainStore { headers: { 'x-jwt': info?.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); if (response.status) { @@ -1786,7 +1787,7 @@ export class MainStore { headers: { 'x-jwt': info.jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -1808,7 +1809,7 @@ export class MainStore { headers: { 'x-jwt': info.jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -1899,7 +1900,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2080,7 +2081,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2179,7 +2180,7 @@ export class MainStore { }, { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } ); return data; @@ -2206,7 +2207,7 @@ export class MainStore { }, { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } ); return data; @@ -2231,7 +2232,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2266,7 +2267,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2289,7 +2290,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2309,7 +2310,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2334,7 +2335,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2379,7 +2380,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2428,7 +2429,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2450,7 +2451,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2478,7 +2479,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2502,7 +2503,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2530,7 +2531,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2554,7 +2555,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2576,7 +2577,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2597,7 +2598,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2618,7 +2619,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2639,7 +2640,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2661,7 +2662,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2683,7 +2684,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2708,7 +2709,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2731,7 +2732,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } } ); @@ -2754,7 +2755,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2772,7 +2773,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2795,7 +2796,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2812,7 +2813,7 @@ export class MainStore { mode: 'cors', headers: { 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2846,7 +2847,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2870,7 +2871,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2891,7 +2892,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r.json(); @@ -2911,7 +2912,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r; @@ -2931,7 +2932,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); return r; @@ -2950,7 +2951,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2970,7 +2971,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -2990,7 +2991,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3015,7 +3016,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3041,7 +3042,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3066,7 +3067,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3086,7 +3087,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3107,7 +3108,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3128,7 +3129,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3149,7 +3150,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3174,7 +3175,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3196,7 +3197,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3234,7 +3235,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3256,7 +3257,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3278,7 +3279,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3308,7 +3309,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3347,7 +3348,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3387,7 +3388,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3428,7 +3429,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3464,7 +3465,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3498,7 +3499,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3519,7 +3520,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3542,7 +3543,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); if (!response.ok) { @@ -3566,7 +3567,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }, body: JSON.stringify(repo) }); @@ -3594,7 +3595,7 @@ export class MainStore { const headers = { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }; const body = JSON.stringify(repo); @@ -3627,7 +3628,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } } ); @@ -3655,7 +3656,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); if (!response.ok) { @@ -3684,7 +3685,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3711,7 +3712,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } } ); @@ -3734,7 +3735,7 @@ export class MainStore { const headers = { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }; const body = JSON.stringify(phase); @@ -3762,7 +3763,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3795,7 +3796,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }, body: JSON.stringify(ticketPayload) }); @@ -3823,7 +3824,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }, body: JSON.stringify(payload) }); @@ -3851,7 +3852,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3898,7 +3899,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3919,7 +3920,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } }); @@ -3944,7 +3945,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId }, body: JSON.stringify(codeGraph) }); @@ -3972,7 +3973,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - 'session_id': this.sessionId + 'x-session-id': this.sessionId } } ); From 401d0812c9a9cd8581e3d0ac28b58f7cae30287f Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Wed, 1 Jan 2025 00:24:24 +0500 Subject: [PATCH 05/11] fix prettier and cypress --- src/store/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/main.ts b/src/store/main.ts index 7b057283..6ebadf6f 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -2116,11 +2116,11 @@ export class MainStore { } initializeSessionId() { - let sessionId = sessionStorage.getItem('sphinx_session_id'); + let sessionId = localStorage.getItem('sphinx_session_id'); if (!sessionId) { sessionId = randomString(32); - sessionStorage.setItem('sphinx_session_id', sessionId); + localStorage.setItem('sphinx_session_id', sessionId); } this.setSessionId(sessionId); From 26150a3d133c398e514027096b938d319817e762 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Thu, 2 Jan 2025 00:39:27 +0500 Subject: [PATCH 06/11] fix cypress --- src/store/main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/store/main.ts b/src/store/main.ts index 6ebadf6f..4c51e3ec 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -1496,8 +1496,7 @@ export class MainStore { headers: { 'x-jwt': info.tribe_jwt, 'Content-Type': 'application/json', - Accept: 'application/json', - 'x-session-id': this.sessionId + Accept: 'application/json' } }); From 7b2d1515cae36524ac9f46eeb5ff371ade3be2b0 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Thu, 2 Jan 2025 08:37:42 +0500 Subject: [PATCH 07/11] fix cypress --- cypress/support/e2e.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index fcc3e63b..fbf85398 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -17,10 +17,27 @@ import './commands'; import nodes from '../fixtures/nodes.json'; import nodesv2 from '../fixtures/v2nodes.json'; +import { randomString } from '../../src/helpers/helpers-extended'; // Alternatively you can use CommonJS syntax: // require('./commands') +const sessionId = randomString(32); + +before(() => { + localStorage.setItem('sphinx_session_id', sessionId); +}); + +beforeEach(() => { + if (!localStorage.getItem('sphinx_session_id')) { + localStorage.setItem('sphinx_session_id', sessionId); + } + + cy.intercept('**/*', (req: any) => { + req.headers['x-session-id'] = localStorage.getItem('sphinx_session_id'); + }); +}); + async function postAllUsersToTribe() { for (let i = 0; i < nodes.length; i++) { const node = nodes[i]; From 4ece2a540207fe8671dbc24c7c3cc62cf4662b3f Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Thu, 2 Jan 2025 11:31:15 +0500 Subject: [PATCH 08/11] fix cypress with sessionStorage --- cypress/support/e2e.ts | 8 ++++---- src/store/main.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index fbf85398..ff01d032 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -25,16 +25,16 @@ import { randomString } from '../../src/helpers/helpers-extended'; const sessionId = randomString(32); before(() => { - localStorage.setItem('sphinx_session_id', sessionId); + sessionStorage.setItem('sphinx_session_id', sessionId); }); beforeEach(() => { - if (!localStorage.getItem('sphinx_session_id')) { - localStorage.setItem('sphinx_session_id', sessionId); + if (!sessionStorage.getItem('sphinx_session_id')) { + sessionStorage.setItem('sphinx_session_id', sessionId); } cy.intercept('**/*', (req: any) => { - req.headers['x-session-id'] = localStorage.getItem('sphinx_session_id'); + req.headers['x-session-id'] = sessionStorage.getItem('sphinx_session_id'); }); }); diff --git a/src/store/main.ts b/src/store/main.ts index 4c51e3ec..1d7c83c6 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -2115,11 +2115,11 @@ export class MainStore { } initializeSessionId() { - let sessionId = localStorage.getItem('sphinx_session_id'); + let sessionId = sessionStorage.getItem('sphinx_session_id'); if (!sessionId) { sessionId = randomString(32); - localStorage.setItem('sphinx_session_id', sessionId); + sessionStorage.setItem('sphinx_session_id', sessionId); } this.setSessionId(sessionId); From 0623ee3ae55525ccf6bacaa5cacffb0a86de80d9 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Fri, 3 Jan 2025 06:26:10 +0500 Subject: [PATCH 09/11] fix cypress --- cypress/e2e/23_editWorkspaceDetails.cy.ts | 6 +++--- cypress/e2e/42_rolesWithdrawWorkspace.cy.ts | 4 ---- cypress/e2e/43_rolesFundWorkspace.cy.ts | 4 ---- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/cypress/e2e/23_editWorkspaceDetails.cy.ts b/cypress/e2e/23_editWorkspaceDetails.cy.ts index 919b1f48..7d829941 100644 --- a/cypress/e2e/23_editWorkspaceDetails.cy.ts +++ b/cypress/e2e/23_editWorkspaceDetails.cy.ts @@ -12,16 +12,16 @@ describe('Edit Workspace Details', () => { website: 'https://updated.org' }; - before(() => { + it('should edit workspace details successfully', () => { cy.login(workspace.loggedInAs); cy.wait(1000); + cy.contains(workspace.loggedInAs).click(); cy.wait(1000); + cy.create_workspace(workspace); cy.wait(1000); - }); - it('should edit workspace details successfully', () => { cy.contains(workspace.name).get(`[data-work-name="${workspace.name}"]`).click(); cy.wait(1000); diff --git a/cypress/e2e/42_rolesWithdrawWorkspace.cy.ts b/cypress/e2e/42_rolesWithdrawWorkspace.cy.ts index 09577ce0..80493579 100644 --- a/cypress/e2e/42_rolesWithdrawWorkspace.cy.ts +++ b/cypress/e2e/42_rolesWithdrawWorkspace.cy.ts @@ -9,10 +9,6 @@ describe('Withdraw From Workspace Role Test', () => { github: 'https://github.com/amazing' }; - beforeEach(() => { - cy.clearCookies(); - }); - it('should allow a user with a Withdraw From Workspace role to withdraw from the workspace', () => { cy.login(workspace.loggedInAs); cy.wait(1000); diff --git a/cypress/e2e/43_rolesFundWorkspace.cy.ts b/cypress/e2e/43_rolesFundWorkspace.cy.ts index f9217663..51e4f49c 100644 --- a/cypress/e2e/43_rolesFundWorkspace.cy.ts +++ b/cypress/e2e/43_rolesFundWorkspace.cy.ts @@ -9,10 +9,6 @@ describe('Fund Workspace Role Test', () => { github: 'https://github.com/amazing' }; - beforeEach(() => { - cy.clearCookies(); - }); - it('Should allow a user with a Fund Workspave role to deposit into the workspace', () => { cy.login(workspace.loggedInAs); cy.wait(1000); From f22367a8f59bee51fb74d190f2f4030e32ed86f2 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Sat, 4 Jan 2025 05:19:20 +0500 Subject: [PATCH 10/11] fix cypress --- cypress.config.ts | 10 ++-- cypress/e2e/32_bountyModalNavigation.cy.ts | 60 +++++++++++----------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index 07a84b39..c907c07f 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,12 +1,16 @@ -import { defineConfig } from "cypress"; +import { defineConfig } from 'cypress'; export default defineConfig({ viewportWidth: 1800, viewportHeight: 1200, video: true, e2e: { + retries: { + runMode: 3, + openMode: 1 + }, setupNodeEvents(on, config) { // implement node event listeners here - }, - }, + } + } }); diff --git a/cypress/e2e/32_bountyModalNavigation.cy.ts b/cypress/e2e/32_bountyModalNavigation.cy.ts index 240e0b81..6e81a3a7 100644 --- a/cypress/e2e/32_bountyModalNavigation.cy.ts +++ b/cypress/e2e/32_bountyModalNavigation.cy.ts @@ -1,8 +1,8 @@ describe('Alice tries to create 8 bounties and then assert that he can go to the next and previous bounties', () => { it('Create 8 bounties and assert next and previous bounties', () => { - let activeUser = 'alice'; + let activeUser = 'bob'; cy.login(activeUser); - cy.wait(1000); + cy.wait(2000); const assignees = ['', '', '', 'carol', 'carol', 'carol', 'carol', 'carol']; @@ -12,105 +12,105 @@ describe('Alice tries to create 8 bounties and then assert that he can go to the category: 'Web development', coding_language: ['Typescript'], description: 'Lorem Ipsum Dolor', - amount: '10000', + amount: '20000', assign: assignees[i], deliverables: 'We are good to go man', tribe: '', estimate_session_length: 'Less than 3 hour', estimate_completion_date: '09/09/2024' }); - cy.wait(1000); + cy.wait(2000); if (i > 5) { if (i === 6) { cy.contains('Filter').click(); cy.contains('Assigned').click(); - cy.wait(1000); + cy.wait(2000); } cy.contains(`Navigation Bounty Title ${i}`).click(); - cy.wait(1000); + cy.wait(2000); cy.contains('Mark as Paid').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('Next').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('Skip and Mark Paid').click(); - cy.wait(1000); + cy.wait(2000); cy.get('body').click(0, 0); - cy.wait(1000); + cy.wait(2000); } } cy.contains('Filter').click(); cy.contains('Assigned').click(); - cy.wait(1000); + cy.wait(2000); for (let i = 0; i < 3; i++) { cy.contains(`Navigation Bounty Title ${i}`); } cy.contains('Navigation Bounty Title 0').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('chevron_right').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('chevron_left').click(); - cy.wait(1000); + cy.wait(2000); - cy.get('[data-testid="close-btn"]').click(0, 0); - cy.wait(1000); + cy.get('[data-testid="close-btn"]').click({ force: true }); + cy.wait(2000); cy.contains('Filter').click(); cy.contains('Paid').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('Navigation Bounty Title 6'); cy.contains('Navigation Bounty Title 7'); cy.contains('Navigation Bounty Title 6').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('chevron_right').click(); - cy.wait(1000); + cy.wait(2000); - cy.get('[data-testid="close-btn"]').click(0, 0); - cy.wait(1000); + cy.get('[data-testid="close-btn"]').click({ force: true }); + cy.wait(2000); cy.contains('Filter').click(); cy.contains('Assigned').click(); - cy.wait(1000); + cy.wait(2000); for (let i = 0; i < 8; i++) { cy.contains(`Navigation Bounty Title ${i}`); } cy.contains('Navigation Bounty Title 1').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('chevron_left').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('Navigation Bounty Title 0'); - cy.wait(1000); + cy.wait(2000); cy.contains('chevron_right').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('Navigation Bounty Title 1'); - cy.wait(1000); + cy.wait(2000); cy.contains('chevron_right').click(); - cy.wait(1000); + cy.wait(2000); cy.contains('Navigation Bounty Title 2'); - cy.wait(1000); + cy.wait(2000); - cy.get('[data-testid="close-btn"]').click(0, 0); + cy.get('[data-testid="close-btn"]').click({ force: true }); cy.logout(activeUser); }); }); From 8d6a1068bab2084796a0b5d78ea0527b4a83e026 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Sat, 4 Jan 2025 07:54:41 +0500 Subject: [PATCH 11/11] fix cypress --- cypress/e2e/31_editBountyBySearch.cy.ts | 6 +++--- cypress/support/commands.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cypress/e2e/31_editBountyBySearch.cy.ts b/cypress/e2e/31_editBountyBySearch.cy.ts index 9099c886..e2f0d473 100644 --- a/cypress/e2e/31_editBountyBySearch.cy.ts +++ b/cypress/e2e/31_editBountyBySearch.cy.ts @@ -48,7 +48,7 @@ describe('Edit Bounty By Searching, Change Workspace And Assignee', () => { it('should be able to edit a bounty by searching, changing workspace, amount, coding languages, and assignee', () => { cy.create_bounty(bounty); - cy.wait(1000); + cy.wait(2000); // Search for the bounty cy.get('input').type(bounty.title); @@ -78,7 +78,7 @@ describe('Edit Bounty By Searching, Change Workspace And Assignee', () => { cy.get('[data-testid="org_uuid"]').should('exist').click({ force: true }).wait(5000); cy.wait(1000); cy.contains(bounty.workspace).should('exist').click({ force: true }); - + cy.wait(1000); // Assign a new assignee cy.get('.SearchInput').type(NewAssignee); cy.wait(1000); @@ -106,7 +106,7 @@ describe('Edit Bounty By Searching, Change Workspace And Assignee', () => { cy.get('[data-testid="close-btn"]').click(0, 0); cy.visit('http://localhost:3007/bounties'); - cy.wait(1000); + cy.wait(5000); // Verify the bounty changes cy.get('input').type(bounty.title); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index ef6d6b77..a492a8a4 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -56,6 +56,7 @@ Cypress.Commands.add('login', (userAlias: string) => { } cy.visit('http://localhost:3007'); + cy.wait(2000); cy.contains('Sign in').click(); cy.get('[data-challenge]') @@ -342,6 +343,7 @@ Cypress.Commands.add('lnurl_login', (seed: string): Cypress.Chainable => } cy.visit('http://localhost:3007'); + cy.wait(2000); cy.contains('Sign in').click(); cy.contains('Login with LNAUTH').click(); @@ -396,7 +398,7 @@ Cypress.Commands.add('lnurl_login', (seed: string): Cypress.Chainable => }); Cypress.Commands.add('clickAlias', (expectedAlias) => { - cy.wait(2000); + cy.wait(3000); cy.get('[data-testid="loggedInUser"]').within(() => { cy.get('[data-testid="alias"]') .should(($el) => {