|
1 | 1 | import type { Clock } from '../../../test' |
2 | | -import { mockClock, createFakeSessionStoreStrategy, mockExperimentalFeatures } from '../../../test' |
| 2 | +import { mockClock, createFakeSessionStoreStrategy } from '../../../test' |
3 | 3 | import type { InitConfiguration, Configuration } from '../configuration' |
4 | 4 | import { display } from '../../tools/display' |
5 | | -import { ExperimentalFeature } from '../../tools/experimentalFeatures' |
6 | 5 | import type { SessionStore } from './sessionStore' |
7 | 6 | import { STORAGE_POLL_DELAY, startSessionStore, selectSessionStoreStrategyType } from './sessionStore' |
8 | 7 | import { |
@@ -466,115 +465,94 @@ describe('session store', () => { |
466 | 465 | }) |
467 | 466 |
|
468 | 467 | describe('regular watch', () => { |
469 | | - ;[true, false].forEach((useExperimentalFeature) => { |
470 | | - describe(`when 'watch_cookie_without_lock' experimental feature is ${useExperimentalFeature}`, () => { |
471 | | - beforeEach(() => { |
472 | | - if (useExperimentalFeature) { |
473 | | - mockExperimentalFeatures([ExperimentalFeature.WATCH_COOKIE_WITHOUT_LOCK]) |
474 | | - } |
475 | | - }) |
476 | | - |
477 | | - it('when session not in cache and session not in store, should store the expired session', () => { |
478 | | - setupSessionStore() |
479 | | - |
480 | | - clock.tick(STORAGE_POLL_DELAY) |
481 | | - |
482 | | - expectSessionToBeExpiredInStore() |
483 | | - expect(sessionStoreManager.getSession().id).toBeUndefined() |
484 | | - expect(expireSpy).not.toHaveBeenCalled() |
485 | | - expect(sessionStoreStrategy.persistSession).toHaveBeenCalled() |
486 | | - }) |
487 | | - |
488 | | - it('when session in cache and session not in store, should expire session', () => { |
489 | | - setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
490 | | - resetSessionInStore() |
491 | | - |
492 | | - clock.tick(STORAGE_POLL_DELAY) |
493 | | - |
494 | | - expect(sessionStoreManager.getSession().id).toBeUndefined() |
495 | | - expectSessionToBeExpiredInStore() |
496 | | - expect(expireSpy).toHaveBeenCalled() |
497 | | - expect(sessionStoreStrategy.persistSession).toHaveBeenCalled() |
498 | | - }) |
499 | | - |
500 | | - it('when session not in cache and session in store, should do nothing', () => { |
501 | | - setupSessionStore() |
502 | | - setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
503 | | - |
504 | | - clock.tick(STORAGE_POLL_DELAY) |
505 | | - |
506 | | - expect(sessionStoreManager.getSession().id).toBeUndefined() |
507 | | - expect(expireSpy).not.toHaveBeenCalled() |
508 | | - if (useExperimentalFeature) { |
509 | | - expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
510 | | - } |
511 | | - }) |
512 | | - |
513 | | - it('when session in cache is same session than in store, should synchronize session', () => { |
514 | | - setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
515 | | - setSessionInStore( |
516 | | - createSessionState(FakeTrackingType.TRACKED, FIRST_ID, Date.now() + SESSION_TIME_OUT_DELAY + 10) |
517 | | - ) |
518 | | - |
519 | | - clock.tick(STORAGE_POLL_DELAY) |
520 | | - |
521 | | - expect(sessionStoreManager.getSession().id).toBe(FIRST_ID) |
522 | | - expect(sessionStoreManager.getSession().expire).toBe(getStoreExpiration()) |
523 | | - expect(expireSpy).not.toHaveBeenCalled() |
524 | | - if (useExperimentalFeature) { |
525 | | - expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
526 | | - } |
527 | | - }) |
528 | | - |
529 | | - it('when session id in cache is different than session id in store, should expire session and not touch the store', () => { |
530 | | - setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
531 | | - setSessionInStore(createSessionState(FakeTrackingType.TRACKED, SECOND_ID)) |
532 | | - |
533 | | - clock.tick(STORAGE_POLL_DELAY) |
534 | | - |
535 | | - expect(sessionStoreManager.getSession().id).toBeUndefined() |
536 | | - expect(expireSpy).toHaveBeenCalled() |
537 | | - if (useExperimentalFeature) { |
538 | | - expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
539 | | - } |
540 | | - }) |
541 | | - |
542 | | - it('when session in store is expired first and then get updated by another tab, should expire session in cache and not touch the store', () => { |
543 | | - setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
544 | | - resetSessionInStore() |
545 | | - |
546 | | - // Simulate a new session being written to the store by another tab during the watch |
547 | | - // when the experimental feature is enabled, watch is reading the cookie twice so we need to plan the write of the cookie at the right index |
548 | | - sessionStoreStrategy.planRetrieveSession( |
549 | | - useExperimentalFeature ? 1 : 0, |
550 | | - createSessionState(FakeTrackingType.TRACKED, SECOND_ID) |
551 | | - ) |
552 | | - |
553 | | - clock.tick(STORAGE_POLL_DELAY) |
554 | | - |
555 | | - // expires session in cache |
556 | | - expect(sessionStoreManager.getSession().id).toBeUndefined() |
557 | | - expect(expireSpy).toHaveBeenCalled() |
558 | | - |
559 | | - // Does not touch the store |
560 | | - // The two calls to persist session are for the lock management, these can be ignored |
561 | | - expect(sessionStoreStrategy.persistSession).toHaveBeenCalledTimes(2) |
562 | | - expect(sessionStoreStrategy.expireSession).not.toHaveBeenCalled() |
563 | | - }) |
564 | | - |
565 | | - it('when session type in cache is different than session type in store, should expire session and not touch the store', () => { |
566 | | - setupSessionStore(createSessionState(FakeTrackingType.NOT_TRACKED, FIRST_ID)) |
567 | | - setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
568 | | - |
569 | | - clock.tick(STORAGE_POLL_DELAY) |
570 | | - |
571 | | - expect(sessionStoreManager.getSession().id).toBeUndefined() |
572 | | - expect(expireSpy).toHaveBeenCalled() |
573 | | - if (useExperimentalFeature) { |
574 | | - expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
575 | | - } |
576 | | - }) |
577 | | - }) |
| 468 | + it('when session not in cache and session not in store, should store the expired session', () => { |
| 469 | + setupSessionStore() |
| 470 | + |
| 471 | + clock.tick(STORAGE_POLL_DELAY) |
| 472 | + |
| 473 | + expectSessionToBeExpiredInStore() |
| 474 | + expect(sessionStoreManager.getSession().id).toBeUndefined() |
| 475 | + expect(expireSpy).not.toHaveBeenCalled() |
| 476 | + expect(sessionStoreStrategy.persistSession).toHaveBeenCalled() |
| 477 | + }) |
| 478 | + |
| 479 | + it('when session in cache and session not in store, should expire session', () => { |
| 480 | + setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
| 481 | + resetSessionInStore() |
| 482 | + |
| 483 | + clock.tick(STORAGE_POLL_DELAY) |
| 484 | + |
| 485 | + expect(sessionStoreManager.getSession().id).toBeUndefined() |
| 486 | + expectSessionToBeExpiredInStore() |
| 487 | + expect(expireSpy).toHaveBeenCalled() |
| 488 | + expect(sessionStoreStrategy.persistSession).toHaveBeenCalled() |
| 489 | + }) |
| 490 | + |
| 491 | + it('when session not in cache and session in store, should do nothing', () => { |
| 492 | + setupSessionStore() |
| 493 | + setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
| 494 | + |
| 495 | + clock.tick(STORAGE_POLL_DELAY) |
| 496 | + |
| 497 | + expect(sessionStoreManager.getSession().id).toBeUndefined() |
| 498 | + expect(expireSpy).not.toHaveBeenCalled() |
| 499 | + expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
| 500 | + }) |
| 501 | + |
| 502 | + it('when session in cache is same session than in store, should synchronize session', () => { |
| 503 | + setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
| 504 | + setSessionInStore( |
| 505 | + createSessionState(FakeTrackingType.TRACKED, FIRST_ID, Date.now() + SESSION_TIME_OUT_DELAY + 10) |
| 506 | + ) |
| 507 | + |
| 508 | + clock.tick(STORAGE_POLL_DELAY) |
| 509 | + |
| 510 | + expect(sessionStoreManager.getSession().id).toBe(FIRST_ID) |
| 511 | + expect(sessionStoreManager.getSession().expire).toBe(getStoreExpiration()) |
| 512 | + expect(expireSpy).not.toHaveBeenCalled() |
| 513 | + expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
| 514 | + }) |
| 515 | + |
| 516 | + it('when session id in cache is different than session id in store, should expire session and not touch the store', () => { |
| 517 | + setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
| 518 | + setSessionInStore(createSessionState(FakeTrackingType.TRACKED, SECOND_ID)) |
| 519 | + |
| 520 | + clock.tick(STORAGE_POLL_DELAY) |
| 521 | + |
| 522 | + expect(sessionStoreManager.getSession().id).toBeUndefined() |
| 523 | + expect(expireSpy).toHaveBeenCalled() |
| 524 | + expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
| 525 | + }) |
| 526 | + |
| 527 | + it('when session in store is expired first and then get updated by another tab, should expire session in cache and not touch the store', () => { |
| 528 | + setupSessionStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
| 529 | + resetSessionInStore() |
| 530 | + |
| 531 | + // Simulate a new session being written to the store by another tab during the watch. |
| 532 | + // Watch is reading the cookie twice so we need to plan the write of the cookie at the right index |
| 533 | + sessionStoreStrategy.planRetrieveSession(1, createSessionState(FakeTrackingType.TRACKED, SECOND_ID)) |
| 534 | + |
| 535 | + clock.tick(STORAGE_POLL_DELAY) |
| 536 | + |
| 537 | + // expires session in cache |
| 538 | + expect(sessionStoreManager.getSession().id).toBeUndefined() |
| 539 | + expect(expireSpy).toHaveBeenCalled() |
| 540 | + |
| 541 | + // Does not touch the store |
| 542 | + // The two calls to persist session are for the lock management, these can be ignored |
| 543 | + expect(sessionStoreStrategy.persistSession).toHaveBeenCalledTimes(2) |
| 544 | + expect(sessionStoreStrategy.expireSession).not.toHaveBeenCalled() |
| 545 | + }) |
| 546 | + |
| 547 | + it('when session type in cache is different than session type in store, should expire session and not touch the store', () => { |
| 548 | + setupSessionStore(createSessionState(FakeTrackingType.NOT_TRACKED, FIRST_ID)) |
| 549 | + setSessionInStore(createSessionState(FakeTrackingType.TRACKED, FIRST_ID)) |
| 550 | + |
| 551 | + clock.tick(STORAGE_POLL_DELAY) |
| 552 | + |
| 553 | + expect(sessionStoreManager.getSession().id).toBeUndefined() |
| 554 | + expect(expireSpy).toHaveBeenCalled() |
| 555 | + expect(sessionStoreStrategy.persistSession).not.toHaveBeenCalled() |
578 | 556 | }) |
579 | 557 | }) |
580 | 558 |
|
|
0 commit comments