-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14007 from nextcloud/fix/noid/groupware-store
fix(integrations): move groupware-related API to dedicated store
- Loading branch information
Showing
11 changed files
with
275 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import axios from '@nextcloud/axios' | ||
import { generateOcsUrl } from '@nextcloud/router' | ||
|
||
import type { | ||
OutOfOfficeResponse, | ||
UpcomingEventsResponse, | ||
} from '../types/index.ts' | ||
|
||
/** | ||
* Get upcoming events for a given conversation within the next 31 days. | ||
* @param location conversation's absolute URL | ||
*/ | ||
const getUpcomingEvents = async (location: string): UpcomingEventsResponse => { | ||
return axios.get(generateOcsUrl('/apps/dav/api/v1/events/upcoming'), { | ||
params: { | ||
location, | ||
}, | ||
}) | ||
} | ||
|
||
/** | ||
* Get absence information for a user (in a given 1-1 conversation). | ||
* @param userId user id | ||
*/ | ||
const getUserAbsence = async (userId: string): OutOfOfficeResponse => { | ||
return axios.get(generateOcsUrl('/apps/dav/api/v1/outOfOffice/{userId}/now', { userId })) | ||
} | ||
|
||
export { | ||
getUpcomingEvents, | ||
getUserAbsence, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import { setActivePinia, createPinia } from 'pinia' | ||
|
||
import { getUserAbsence } from '../../services/groupwareService.ts' | ||
import { generateOCSErrorResponse, generateOCSResponse } from '../../test-helpers.js' | ||
import { useGroupwareStore } from '../groupware.ts' | ||
|
||
jest.mock('../../services/groupwareService', () => ({ | ||
getUserAbsence: jest.fn(), | ||
})) | ||
|
||
describe('groupwareStore', () => { | ||
const token = 'TOKEN' | ||
const userId = 'alice' | ||
const payload = { id: 1, userId: 'alice', firstDay: '2023-11-15', lastDay: '2023-11-17', status: 'absence status', message: 'absence message' } | ||
let groupwareStore | ||
|
||
beforeEach(async () => { | ||
setActivePinia(createPinia()) | ||
groupwareStore = useGroupwareStore() | ||
}) | ||
|
||
afterEach(async () => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('absence status', () => { | ||
it('processes a response from server and stores absence status', async () => { | ||
// Arrange | ||
const response = generateOCSResponse({ payload }) | ||
getUserAbsence.mockResolvedValueOnce(response) | ||
|
||
// Act | ||
await groupwareStore.getUserAbsence({ token, userId }) | ||
|
||
// Assert | ||
expect(getUserAbsence).toHaveBeenCalledWith(userId) | ||
expect(groupwareStore.absence[token]).toEqual(payload) | ||
}) | ||
|
||
it('does not show error if absence status is not found', async () => { | ||
// Arrange | ||
const errorNotFound = generateOCSErrorResponse({ payload: null, status: 404 }) | ||
const errorOther = generateOCSErrorResponse({ payload: null, status: 500 }) | ||
getUserAbsence | ||
.mockRejectedValueOnce(errorNotFound) | ||
.mockRejectedValueOnce(errorOther) | ||
console.error = jest.fn() | ||
|
||
// Act | ||
await groupwareStore.getUserAbsence({ token, userId }) | ||
await groupwareStore.getUserAbsence({ token, userId }) | ||
|
||
// Assert | ||
expect(getUserAbsence).toHaveBeenCalledTimes(2) | ||
expect(console.error).toHaveBeenCalledTimes(1) | ||
expect(groupwareStore.absence[token]).toEqual(null) | ||
}) | ||
|
||
it('removes absence status from the store', async () => { | ||
// Arrange | ||
const response = generateOCSResponse({ payload }) | ||
getUserAbsence.mockResolvedValueOnce(response) | ||
const token2 = 'TOKEN_2' | ||
|
||
// Act | ||
await groupwareStore.getUserAbsence({ token, userId }) | ||
groupwareStore.removeUserAbsence(token) | ||
groupwareStore.removeUserAbsence(token2) | ||
|
||
// Assert | ||
expect(groupwareStore.absence[token]).not.toBeDefined() | ||
expect(groupwareStore.absence[token2]).not.toBeDefined() | ||
}) | ||
}) | ||
|
||
describe('purge store', () => { | ||
it('clears store for provided token', async () => { | ||
// Arrange | ||
const response = generateOCSResponse({ payload }) | ||
getUserAbsence.mockResolvedValueOnce(response) | ||
|
||
await groupwareStore.getUserAbsence({ token: 'token-1', userId }) | ||
|
||
// Act | ||
groupwareStore.purgeGroupwareStore('token-1') | ||
|
||
// Assert | ||
expect(groupwareStore.absence['token-1']).not.toBeDefined() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.