123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import { createPinia, setActivePinia } from 'pinia'
- import {
- mockGraphQLApi,
- mockGraphQLSubscription,
- } from '#tests/support/mock-graphql-api.ts'
- import { CurrentUserDocument } from '#shared/graphql/queries/currentUser.api.ts'
- import { CurrentUserUpdatesDocument } from '#shared/graphql/subscriptions/currentUserUpdates.api.ts'
- import { useSessionStore } from '../session.ts'
- const userData = {
- __typename: 'User',
- id: '123456789',
- internalId: 1,
- firstname: 'John',
- lastname: 'Doe',
- fullname: 'John Doe',
- email: 'zammad@example.com',
- image: 'c2715a3e92c7e375b8c212d25d431e2a',
- preferences: {
- locale: 'de-de',
- },
- personalSettings: {
- __typename: 'UserPersonalSettings',
- notificationConfig: {
- __typename: 'UserPersonalSettingsNotificationConfig',
- groupIds: [1],
- matrix: {
- __typename: 'UserPersonalSettingsNotificationMatrix',
- create: {
- __typename: 'UserPersonalSettingsNotificationMatrixRow',
- channel: {
- __typename: 'UserPersonalSettingsNotificationMatrixChannel',
- email: true,
- online: true,
- },
- criteria: {
- __typename: 'UserPersonalSettingsNotificationMatrixCriteria',
- no: false,
- ownedByMe: true,
- ownedByNobody: true,
- subscribed: true,
- },
- },
- escalation: {
- __typename: 'UserPersonalSettingsNotificationMatrixRow',
- channel: {
- __typename: 'UserPersonalSettingsNotificationMatrixChannel',
- email: true,
- online: true,
- },
- criteria: {
- __typename: 'UserPersonalSettingsNotificationMatrixCriteria',
- no: false,
- ownedByMe: true,
- ownedByNobody: true,
- subscribed: true,
- },
- },
- reminderReached: {
- __typename: 'UserPersonalSettingsNotificationMatrixRow',
- channel: {
- __typename: 'UserPersonalSettingsNotificationMatrixChannel',
- email: true,
- online: true,
- },
- criteria: {
- __typename: 'UserPersonalSettingsNotificationMatrixCriteria',
- no: false,
- ownedByMe: true,
- ownedByNobody: true,
- subscribed: true,
- },
- },
- update: {
- __typename: 'UserPersonalSettingsNotificationMatrixRow',
- channel: {
- __typename: 'UserPersonalSettingsNotificationMatrixChannel',
- email: true,
- online: true,
- },
- criteria: {
- __typename: 'UserPersonalSettingsNotificationMatrixCriteria',
- no: false,
- ownedByMe: true,
- ownedByNobody: true,
- subscribed: true,
- },
- },
- },
- },
- notificationSound: {
- __typename: 'UserPersonalSettingsNotificationSound',
- enabled: true,
- file: 'Ring',
- },
- },
- objectAttributeValues: [],
- authorizations: [],
- organization: {
- __typename: 'Organization',
- id: '234241',
- internalId: 1,
- name: 'Zammad Foundation',
- objectAttributeValues: [],
- active: true,
- },
- permissions: {
- __typename: 'Permission',
- names: ['admin'],
- },
- hasSecondaryOrganizations: false,
- outOfOffice: false,
- outOfOfficeStartAt: null,
- outOfOfficeEndAt: null,
- outOfOfficeReplacement: null,
- }
- describe('Session Store', () => {
- beforeEach(() => {
- setActivePinia(createPinia())
- })
- it('is empty by default', () => {
- const session = useSessionStore()
- expect(session.id).toBe(null)
- expect(session.user).toBe(null)
- })
- it('get current user and check on user update subscription', async () => {
- const session = useSessionStore()
- mockGraphQLApi(CurrentUserDocument).willResolve({
- currentUser: userData,
- })
- const userUpdateSubscription = mockGraphQLSubscription(
- CurrentUserUpdatesDocument,
- )
- await session.getCurrentUser()
- expect(session.user).toEqual(userData)
- const updatedUserData = {
- ...userData,
- firstname: 'Jane',
- lastname: 'Doe',
- fullname: 'Jane Doe',
- }
- await userUpdateSubscription.next({
- data: {
- userUpdates: {
- __typename: 'UserUpdatesPayload',
- user: updatedUserData,
- },
- },
- })
- expect(session.user).toEqual(updatedUserData)
- })
- })
|