Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b719ac070 | ||
|
|
baa9045af7 | ||
|
|
b004587262 | ||
|
|
8a7beff339 | ||
|
|
9001eb7795 | ||
|
|
50c4578c2e | ||
|
|
4ff2ce90f9 | ||
|
|
86f8c6c5fa | ||
|
|
0611bbd50e | ||
|
|
b946abab02 | ||
|
|
a091c60618 | ||
|
|
bba7fc1a30 | ||
|
|
864c46736b | ||
|
|
4416709ff6 | ||
|
|
591d42fc8f | ||
|
|
d73b84157a | ||
|
|
680e748b7a | ||
|
|
99b7aaa62d | ||
|
|
3a01e6390f | ||
|
|
a6c25ab7d3 | ||
|
|
df98274a8f | ||
|
|
b540a2ec45 | ||
|
|
8e4459f2fe | ||
|
|
bc5a9f231f | ||
|
|
88984f6175 | ||
|
|
fc592a17ac | ||
|
|
a51524e673 | ||
|
|
cb6553c731 | ||
|
|
101fea2c1c | ||
|
|
aab9193e7b | ||
|
|
a6d2e46b3d | ||
|
|
25ae1493c3 | ||
|
|
56dcab2f6d | ||
|
|
8fbc76d59a | ||
|
|
894c0fc8a7 | ||
|
|
076550b384 | ||
|
|
08e1b0a9c8 | ||
|
|
ef4deb1657 | ||
|
|
f81074c4f5 | ||
|
|
5df14c344e | ||
|
|
cd311f076c | ||
|
|
d60f165223 | ||
|
|
8477128605 | ||
|
|
84606543ae | ||
|
|
a11242e93d | ||
|
|
5939a99aca | ||
|
|
050abd9fab | ||
|
|
1adf2ad5a8 | ||
|
|
3f2d83d89f | ||
|
|
528a4fbb97 | ||
|
|
95e2ad3007 | ||
|
|
c41e5ddc2c | ||
|
|
f206b3d135 | ||
|
|
0b03bcb90e | ||
|
|
b09b32b121 | ||
|
|
d5f7065fdb | ||
|
|
dc40cc664d | ||
|
|
3eaf84e961 | ||
|
|
c36249b5a7 | ||
|
|
3666c260ee | ||
|
|
77f3fd3b38 | ||
|
|
848bcbfb8f | ||
|
|
24936d8b7b | ||
|
|
ad62f9d2bd | ||
|
|
829dd937d6 | ||
|
|
dda4b17a7c | ||
|
|
4def31e98f | ||
|
|
6d3f5495cb | ||
|
|
008af08148 | ||
|
|
ac0930a11f | ||
|
|
0e62800af6 | ||
|
|
b6ab1ef80a | ||
|
|
13347edced | ||
|
|
d734841184 | ||
|
|
a2998b6c84 | ||
|
|
da5df7164a | ||
|
|
3e28160fa7 | ||
|
|
2b9bdb9c80 | ||
|
|
90ce124bbb | ||
|
|
fba3f46779 | ||
|
|
b9a1522abc | ||
|
|
f92a95dc2e | ||
|
|
46acac5dd8 | ||
|
|
8dbd96a2f9 | ||
|
|
3b186b19e6 | ||
|
|
53ec5daa1b | ||
|
|
96b58422fd | ||
|
|
25970e72de | ||
|
|
e5887ec0fa | ||
|
|
e075dcdeaa | ||
|
|
3ab735ba9c | ||
|
|
d429f0ee04 | ||
|
|
3d0a853c4b | ||
|
|
3a46375fed | ||
|
|
07de77ddc6 | ||
|
|
cf45443726 | ||
|
|
629b9391dd | ||
|
|
25da11c497 | ||
|
|
003e2630e7 | ||
|
|
4eef7138c1 | ||
|
|
253d0174be | ||
|
|
5ee5c117c4 | ||
|
|
0f268bbef7 | ||
|
|
d342e3f9e0 | ||
|
|
7f1e20fe19 | ||
|
|
3078423848 | ||
|
|
9953d73444 | ||
|
|
100136aae7 | ||
|
|
3c6e9aaa63 | ||
|
|
8fa39f2ae5 | ||
|
|
3aca72fb06 | ||
|
|
c46905e9a7 | ||
|
|
5ce96c7704 | ||
|
|
23eb77b8ac | ||
|
|
e63edc9d36 | ||
|
|
d33681eddd | ||
|
|
e7816cfb0c | ||
|
|
a268d8743d | ||
|
|
45db5c0d5e | ||
|
|
583661a15d | ||
|
|
461d5e0535 | ||
|
|
099d830e7e | ||
|
|
add59896f5 | ||
|
|
03b97fdb51 | ||
|
|
4c576fbd57 | ||
|
|
06ce1988f3 | ||
|
|
c059d79a51 | ||
|
|
b91c767d0c | ||
|
|
bb29edd30f | ||
|
|
b9a8b613bb | ||
|
|
76377d2d2c | ||
|
|
f4f09eaf9e | ||
|
|
89c08868f6 | ||
|
|
ebab3b701d | ||
|
|
9ffa4b8477 | ||
|
|
c656063b06 | ||
|
|
5b7f2a6ffc | ||
|
|
63c7e4b55a | ||
|
|
24e5226e3e | ||
|
|
9f43c5f1e7 | ||
|
|
b48e3c7bb4 | ||
|
|
a561b805fd | ||
|
|
d21c91c519 | ||
|
|
41e565fcf8 | ||
|
|
2f946fc5da | ||
|
|
06bb7055ac | ||
|
|
1a8492b9c2 | ||
|
|
b8ba95dbb0 | ||
|
|
40df4cf511 | ||
|
|
58cabe974c | ||
|
|
199d95b35f | ||
|
|
c6febad364 | ||
|
|
0ddcc068ce | ||
|
|
3ff3a97c78 | ||
|
|
baaa1fa71e | ||
|
|
27d331ad2d | ||
|
|
9a1a86ed3a | ||
|
|
7902c6157d | ||
|
|
92d0fc6eb4 | ||
|
|
4d0b417925 | ||
|
|
9947b5ec85 | ||
|
|
fa06f38d47 | ||
|
|
99a6b1c7eb | ||
|
|
e3861ad22a | ||
|
|
37caa57798 | ||
|
|
6e66f7f8f8 | ||
|
|
62dd5ea95b | ||
|
|
365dfe9178 | ||
|
|
4d89da99a7 | ||
|
|
6954ad1ea5 | ||
|
|
825573da8e | ||
|
|
2c517f4878 | ||
|
|
8508a6f1a0 | ||
|
|
db03e9db20 | ||
|
|
e6a16f5b5c | ||
|
|
b94aa603c5 | ||
|
|
31e6b88951 | ||
|
|
fbff4db2a6 | ||
|
|
ba61731689 | ||
|
|
e16662e655 | ||
|
|
53c37a9ddf | ||
|
|
64ef2703a5 | ||
|
|
a997edd8db | ||
|
|
bd73eba528 | ||
|
|
0d53c2069e | ||
|
|
3b559525a8 | ||
|
|
33e1abf4a7 | ||
|
|
059c6c37ba | ||
|
|
14bc489d70 | ||
|
|
e8b36d5b0b | ||
|
|
5983c960a6 | ||
|
|
40305b9c5a | ||
|
|
dcc62c6db0 | ||
|
|
07f14e4e14 | ||
|
|
f940f6bd87 | ||
|
|
ca5dcfd1e8 | ||
|
|
324728d4ec | ||
|
|
2f7cc05cad | ||
|
|
84be4dba8d | ||
|
|
17655cd1c8 | ||
|
|
010f5349f6 | ||
|
|
01dead9a1d | ||
|
|
900ea37b43 | ||
|
|
c209c22b98 | ||
|
|
b8610dc2d1 | ||
|
|
28f84d3570 | ||
|
|
b46a902a3d | ||
|
|
de2f51e104 | ||
|
|
35110892c1 | ||
|
|
c870df7027 | ||
|
|
a4b0fdba7b | ||
|
|
b530d31b35 | ||
|
|
a69f9c5fa3 | ||
|
|
73b8569a16 | ||
|
|
5becc95fc4 | ||
|
|
a74522af3d | ||
|
|
8b23e41954 | ||
|
|
94873ea3cb | ||
|
|
0c0cac28fd | ||
|
|
769ca9002e | ||
|
|
03366d2337 | ||
|
|
159fe3a87d | ||
|
|
5b97d3bf52 | ||
|
|
7cdecf57e0 | ||
|
|
1c8d0eda45 | ||
|
|
7ee3f9409c | ||
|
|
0d1dd036eb |
No files matched your search
+9
-3
@@ -15,10 +15,14 @@
|
|||||||
# - You can not repackage or sell the codebase
|
# - You can not repackage or sell the codebase
|
||||||
# - Acquire a commercial license to remove these terms by visiting: cal.com/sales
|
# - Acquire a commercial license to remove these terms by visiting: cal.com/sales
|
||||||
#
|
#
|
||||||
# To enable enterprise-only features, as an admin, go to /auth/setup to select your license and follow
|
|
||||||
# instructions. This environment variable is deprecated although still supported for backward compatibility.
|
# To enable enterprise-only features please add your envrionment variable to the .env file then make your way to /auth/setup to select your license and follow instructions.
|
||||||
# @see https://console.cal.com
|
|
||||||
CALCOM_LICENSE_KEY=
|
CALCOM_LICENSE_KEY=
|
||||||
|
# Signature token for the Cal.com License API (used for self-hosted integrations)
|
||||||
|
# We will give you a token when we provide you with a license key this ensure you and only you can communicate with the Cal.com License API for your license key
|
||||||
|
CAL_SIGNATURE_TOKEN=
|
||||||
|
# The route to the Cal.com License API
|
||||||
|
CALCOM_PRIVATE_API_ROUTE="https://goblin.cal.com"
|
||||||
# ***********************************************************************************************************
|
# ***********************************************************************************************************
|
||||||
|
|
||||||
# - DATABASE ************************************************************************************************
|
# - DATABASE ************************************************************************************************
|
||||||
@@ -255,6 +259,8 @@ NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL=
|
|||||||
# This variable should only be set to 1 or true if you are in a non-prod environment and you want to
|
# This variable should only be set to 1 or true if you are in a non-prod environment and you want to
|
||||||
# use organizations
|
# use organizations
|
||||||
ORGANIZATIONS_ENABLED=
|
ORGANIZATIONS_ENABLED=
|
||||||
|
NEXT_PUBLIC_ORGANIZATIONS_MIN_SELF_SERVE_SEATS=30
|
||||||
|
NEXT_PUBLIC_ORGANIZATIONS_SELF_SERVE_PRICE=3700 # $37.00 per seat
|
||||||
|
|
||||||
# This variable should only be set to 1 or true if you want to autolink external provider sing-ups with
|
# This variable should only be set to 1 or true if you want to autolink external provider sing-ups with
|
||||||
# existing organizations based on email domain address
|
# existing organizations based on email domain address
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Report any issues with the platform
|
|
||||||
title: ""
|
|
||||||
labels: bug
|
|
||||||
assignees: ""
|
|
||||||
---
|
|
||||||
|
|
||||||
Found a bug? Please fill out the sections below. 👍
|
|
||||||
|
|
||||||
### Issue Summary
|
|
||||||
|
|
||||||
A summary of the issue. This needs to be a clear detailed-rich summary.
|
|
||||||
|
|
||||||
### Steps to Reproduce
|
|
||||||
|
|
||||||
1. (for example) Went to ...
|
|
||||||
2. Clicked on...
|
|
||||||
3. ...
|
|
||||||
|
|
||||||
Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?
|
|
||||||
|
|
||||||
### Actual Results
|
|
||||||
|
|
||||||
- What's happening right now that is different from what is expected
|
|
||||||
|
|
||||||
### Expected Results
|
|
||||||
|
|
||||||
- This is an ideal result that the system should get after the tests are performed
|
|
||||||
|
|
||||||
### Technical details
|
|
||||||
|
|
||||||
- Browser version, screen recording, console logs, network requests: You can make a recording with [Bird Eats Bug](https://birdeatsbug.com/).
|
|
||||||
- Node.js version
|
|
||||||
- Anything else that you think could be an issue.
|
|
||||||
|
|
||||||
### Evidence
|
|
||||||
|
|
||||||
- How was this tested? This is quite mandatory in terms of bugs. Providing evidence of your testing with screenshots or/and videos is an amazing way to prove the bug and a troubleshooting chance to find the solution.
|
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
name: Bug report
|
||||||
|
description: "Please make sure you have checked for any duplicate issues."
|
||||||
|
title: "(bug)"
|
||||||
|
labels: ["🐛 bug"]
|
||||||
|
assignees: []
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: issue-summary
|
||||||
|
attributes:
|
||||||
|
label: Issue Summary
|
||||||
|
description: A summary of the issue. This needs to be a clear detailed-rich summary.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: steps-to-reproduce
|
||||||
|
attributes:
|
||||||
|
label: Steps to Reproduce
|
||||||
|
value: |
|
||||||
|
1. (for example) Went to ...
|
||||||
|
2. Clicked on...
|
||||||
|
3. ...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: expected-behavior
|
||||||
|
attributes:
|
||||||
|
label: Expected behavior
|
||||||
|
description: A clear and concise description of what you expected to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: other-information
|
||||||
|
attributes:
|
||||||
|
label: Other information
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
id: screenshots
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: If applicable, add screenshots to help explain your problem.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: checkboxes
|
||||||
|
id: environment
|
||||||
|
attributes:
|
||||||
|
label: Environment
|
||||||
|
options:
|
||||||
|
- label: app.cal.com
|
||||||
|
- label: Self-hosted Cal
|
||||||
|
- type: textarea
|
||||||
|
id: desktop-version
|
||||||
|
attributes:
|
||||||
|
label: Desktop (please complete the following information)
|
||||||
|
description: |
|
||||||
|
examples:
|
||||||
|
- **OS**: [e.g. iOS]
|
||||||
|
- **Browser**: [e.g. chrome, safari]
|
||||||
|
- **Version**: [e.g. 22]
|
||||||
|
value: |
|
||||||
|
- OS:
|
||||||
|
- Node:
|
||||||
|
- npm:
|
||||||
|
render: markdown
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: markdown
|
||||||
|
id: nodejs-version
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
#### Node.JS version
|
||||||
|
|
||||||
|
[e.g. v18.15.0]
|
||||||
|
- type: markdown
|
||||||
|
id: anything-else
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
#### Anything else?
|
||||||
|
|
||||||
|
- Screen recording, console logs, network requests: You can make a recording with [Loom](https://www.loom.com).
|
||||||
|
- Anything else that you think could be an issue?
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
blank_issues_enabled: false
|
blank_issues_enabled: false
|
||||||
contact_links:
|
contact_links:
|
||||||
- name: Questions
|
- name: Questions
|
||||||
url: https://go.cal.com/discord
|
url: https://github.com/calcom/cal.com/discussions
|
||||||
about: Ask a general question about the project on our discord community
|
about: Need help selfhosting or ask a general question about the project? Open a discussion
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
name: Feature request
|
name: Feature request
|
||||||
about: Suggest a feature or idea
|
about: Suggest a feature or idea
|
||||||
title: ""
|
title: ""
|
||||||
labels: feature
|
labels: ["✨ feature", "🚨 needs approval"]
|
||||||
assignees: ""
|
assignees: ""
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -53,3 +53,4 @@ assignees: ""
|
|||||||
- If this issue has a `🚨 needs approval` label, don't start coding yet. Wait until a core member approves feature request by removing this label, then you can start coding.
|
- If this issue has a `🚨 needs approval` label, don't start coding yet. Wait until a core member approves feature request by removing this label, then you can start coding.
|
||||||
- For clarity: Non-core member issues automatically get the `🚨 needs approval` label.
|
- For clarity: Non-core member issues automatically get the `🚨 needs approval` label.
|
||||||
- Your feature ideas are invaluable to us! However, they undergo review to ensure alignment with the product's direction.
|
- Your feature ideas are invaluable to us! However, they undergo review to ensure alignment with the product's direction.
|
||||||
|
- Follow Best Practices lined out in our [Contributor Docs](https://github.com/calcom/cal.com/blob/main/CONTRIBUTING.md)
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
## Mandatory Tasks (DO NOT REMOVE)
|
## Mandatory Tasks (DO NOT REMOVE)
|
||||||
|
|
||||||
- [ ] I have self-reviewed the code (A decent size PR without self-review might be rejected).
|
- [ ] I have self-reviewed the code (A decent size PR without self-review might be rejected).
|
||||||
- [ ] I have added a Docs issue [here](https://github.com/calcom/docs/issues/new) if this PR makes changes that would require a [documentation change](https://docs.cal.com). If N/A, write N/A here and check the checkbox.
|
- [ ] I have added a Docs issue [here](https://github.com/calcom/docs/issues/new) if this PR makes changes that would require a [documentation change](https://docs.cal.com/docs). If N/A, write N/A here and check the checkbox.
|
||||||
- [ ] I confirm automated tests are in place that prove my fix is effective or that my feature works.
|
- [ ] I confirm automated tests are in place that prove my fix is effective or that my feature works.
|
||||||
|
|
||||||
## How should this be tested?
|
## How should this be tested?
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ runs:
|
|||||||
with:
|
with:
|
||||||
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
|
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
|
||||||
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
|
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
|
||||||
restore-keys: |
|
|
||||||
yarn-download-cache-
|
|
||||||
|
|
||||||
# Invalidated on yarn.lock changes
|
# Invalidated on yarn.lock changes
|
||||||
- name: Restore node_modules
|
- name: Restore node_modules
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ description: "Install playwright, cache and restore if necessary"
|
|||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
|
- name: Get installed Playwright version
|
||||||
|
shell: bash
|
||||||
|
id: playwright-version
|
||||||
|
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package.json').devDependencies['@playwright/test'])")" >> $GITHUB_ENV
|
||||||
- name: Cache playwright binaries
|
- name: Cache playwright binaries
|
||||||
id: playwright-cache
|
id: playwright-cache
|
||||||
uses: buildjet/cache@v4
|
uses: buildjet/cache@v4
|
||||||
@@ -11,9 +15,7 @@ runs:
|
|||||||
~/Library/Caches/ms-playwright
|
~/Library/Caches/ms-playwright
|
||||||
~/.cache/ms-playwright
|
~/.cache/ms-playwright
|
||||||
${{ github.workspace }}/node_modules/playwright
|
${{ github.workspace }}/node_modules/playwright
|
||||||
key: cache-playwright-${{ hashFiles('**/yarn.lock') }}
|
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
|
||||||
restore-keys: cache-playwright-
|
|
||||||
- name: Yarn playwright install
|
- name: Yarn playwright install
|
||||||
shell: bash
|
shell: bash
|
||||||
if: steps.playwright-cache.outputs.cache-hit != 'true'
|
run: yarn playwright install --with-deps
|
||||||
run: yarn playwright install
|
|
||||||
@@ -69,12 +69,6 @@ jobs:
|
|||||||
uses: ./.github/workflows/e2e-embed-react.yml
|
uses: ./.github/workflows/e2e-embed-react.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
analyze:
|
|
||||||
name: Analyze Build
|
|
||||||
needs: [build]
|
|
||||||
uses: ./.github/workflows/nextjs-bundle-analysis.yml
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
required:
|
required:
|
||||||
needs: [lint, type-check, unit-test, integration-test, build, build-api-v1, build-api-v2, e2e, e2e-embed, e2e-embed-react, e2e-app-store]
|
needs: [lint, type-check, unit-test, integration-test, build, build-api-v1, build-api-v2, e2e, e2e-embed, e2e-embed-react, e2e-app-store]
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ name: Production Builds
|
|||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
env:
|
env:
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }}
|
CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build API v2
|
name: Build API v2
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
runs-on: buildjet-4vcpu-ubuntu-2204
|
runs-on: buildjet-4vcpu-ubuntu-2204
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
services:
|
services:
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ on:
|
|||||||
workflow_call:
|
workflow_call:
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: --max-old-space-size=4096
|
NODE_OPTIONS: --max-old-space-size=4096
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
jobs:
|
jobs:
|
||||||
check-types:
|
check-types:
|
||||||
runs-on: buildjet-4vcpu-ubuntu-2204
|
runs-on: buildjet-4vcpu-ubuntu-2204
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
name: Delete
|
||||||
|
|
||||||
|
on:
|
||||||
|
delete:
|
||||||
|
branches-ignore: [main, gh-pages]
|
||||||
|
|
||||||
|
# ensures that currently running Playwright workflow of deleted branch gets cancelled
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.event.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
delete_reports:
|
||||||
|
name: Delete Reports
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
# Contains all reports for deleted branch
|
||||||
|
BRANCH_REPORTS_DIR: reports/${{ github.event.ref }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout GitHub Pages Branch
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: gh-pages
|
||||||
|
- name: Set Git User
|
||||||
|
# see: https://github.com/actions/checkout/issues/13#issuecomment-724415212
|
||||||
|
run: |
|
||||||
|
git config --global user.name "github-actions[bot]"
|
||||||
|
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
- name: Check for workflow reports
|
||||||
|
run: |
|
||||||
|
if [ -z "$(ls -A $BRANCH_REPORTS_DIR)" ]; then
|
||||||
|
echo "BRANCH_REPORTS_EXIST="false"" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "BRANCH_REPORTS_EXIST="true"" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
- name: Delete reports from repo for branch
|
||||||
|
if: ${{ env.BRANCH_REPORTS_EXIST == 'true' }}
|
||||||
|
timeout-minutes: 3
|
||||||
|
run: |
|
||||||
|
cd $BRANCH_REPORTS_DIR/..
|
||||||
|
|
||||||
|
rm -rf ${{ github.event.ref }}
|
||||||
|
git add .
|
||||||
|
git commit -m "workflow: remove all reports for branch ${{ github.event.ref }}"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
git pull --rebase
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to rebase. Please review manually."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
git push
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Successfully pushed HTML reports to repo."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
name: E2E
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
env:
|
||||||
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
|
API_KEY_PREFIX: ${{ secrets.CI_API_KEY_PREFIX }}
|
||||||
|
API_PORT: ${{ vars.CI_API_V2_PORT }}
|
||||||
|
CALCOM_LICENSE_KEY: ${{ secrets.CI_CALCOM_LICENSE_KEY }}
|
||||||
|
DAILY_API_KEY: ${{ secrets.CI_DAILY_API_KEY }}
|
||||||
|
DATABASE_URL: ${{ secrets.CI_DATABASE_URL }}
|
||||||
|
DATABASE_READ_URL: ${{ secrets.CI_DATABASE_URL }}
|
||||||
|
DATABASE_WRITE_URL: ${{ secrets.CI_DATABASE_URL }}
|
||||||
|
DATABASE_DIRECT_URL: ${{ secrets.CI_DATABASE_URL }}
|
||||||
|
GOOGLE_API_CREDENTIALS: ${{ secrets.CI_GOOGLE_API_CREDENTIALS }}
|
||||||
|
IS_E2E: true
|
||||||
|
NEXTAUTH_SECRET: ${{ secrets.CI_NEXTAUTH_SECRET }}
|
||||||
|
NEXTAUTH_URL: ${{ secrets.CI_NEXTAUTH_URL }}
|
||||||
|
NODE_OPTIONS: --max-old-space-size=4096
|
||||||
|
REDIS_URL: "redis://localhost:6379"
|
||||||
|
STRIPE_PRIVATE_KEY: ${{ secrets.CI_STRIPE_PRIVATE_KEY }}
|
||||||
|
STRIPE_API_KEY: ${{ secrets.CI_STRIPE_PRIVATE_KEY }}
|
||||||
|
STRIPE_CLIENT_ID: ${{ secrets.CI_STRIPE_CLIENT_ID }}
|
||||||
|
STRIPE_WEBHOOK_SECRET: ${{ secrets.CI_STRIPE_WEBHOOK_SECRET }}
|
||||||
|
jobs:
|
||||||
|
e2e:
|
||||||
|
timeout-minutes: 20
|
||||||
|
name: E2E API v2
|
||||||
|
runs-on: buildjet-8vcpu-ubuntu-2204
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:13
|
||||||
|
credentials:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
env:
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_DB: calendso
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
redis:
|
||||||
|
image: redis:latest
|
||||||
|
ports:
|
||||||
|
- 6379:6379
|
||||||
|
options: >-
|
||||||
|
--health-cmd "redis-cli ping"
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.github/actions/dangerous-git-checkout
|
||||||
|
- uses: ./.github/actions/yarn-install
|
||||||
|
- uses: ./.github/actions/yarn-playwright-install
|
||||||
|
- uses: ./.github/actions/cache-db
|
||||||
|
- name: Run Tests
|
||||||
|
working-directory: apps/api/v2
|
||||||
|
run: |
|
||||||
|
yarn test:e2e
|
||||||
|
EXIT_CODE=$?
|
||||||
|
echo "yarn test:e2e command exit code: $EXIT_CODE"
|
||||||
|
exit $EXIT_CODE
|
||||||
|
- name: Upload Test Results
|
||||||
|
if: ${{ always() }}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: test-results-api-v2
|
||||||
|
path: test-results
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
name: E2E App Store Tests
|
name: E2E App Store Tests
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: --max-old-space-size=4096
|
NODE_OPTIONS: --max-old-space-size=4096
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
@@ -95,5 +98,5 @@ jobs:
|
|||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: app-store-results
|
name: blob-report-app-store
|
||||||
path: test-results
|
path: blob-report
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
name: E2E Embed React tests and booking flow (for non-embed as well)
|
name: E2E Embed React tests and booking flow (for non-embed as well)
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: --max-old-space-size=4096
|
NODE_OPTIONS: --max-old-space-size=4096
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
@@ -82,5 +85,5 @@ jobs:
|
|||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: embed-react-results
|
name: blob-report-embed-react
|
||||||
path: test-results
|
path: blob-report
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
name: E2E Embed Core tests and booking flow (for non-embed as well)
|
name: E2E Embed Core tests and booking flow (for non-embed as well)
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: --max-old-space-size=4096
|
NODE_OPTIONS: --max-old-space-size=4096
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
@@ -88,5 +91,5 @@ jobs:
|
|||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: embed-core-results
|
name: blob-report-embed-core
|
||||||
path: test-results
|
path: blob-report
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
name: E2E
|
name: E2E
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: --max-old-space-size=4096
|
NODE_OPTIONS: --max-old-space-size=4096
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
@@ -86,8 +89,9 @@ jobs:
|
|||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: yarn e2e --shard=${{ matrix.shard }}/${{ strategy.job-total }}
|
run: yarn e2e --shard=${{ matrix.shard }}/${{ strategy.job-total }}
|
||||||
- name: Upload Test Results
|
- name: Upload Test Results
|
||||||
if: ${{ always() }}
|
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
if: always()
|
||||||
with:
|
with:
|
||||||
name: test-results-${{ matrix.shard }}_${{ strategy.job-total }}
|
name: blob-report-${{ matrix.shard }}
|
||||||
path: test-results
|
path: blob-report
|
||||||
|
retention-days: 30
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
name: Integration
|
name: Integration
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: --max-old-space-size=4096
|
NODE_OPTIONS: --max-old-space-size=4096
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
name: Lint
|
name: Lint
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
runs-on: buildjet-4vcpu-ubuntu-2204
|
runs-on: buildjet-4vcpu-ubuntu-2204
|
||||||
@@ -16,13 +19,6 @@ jobs:
|
|||||||
- name: Merge lint reports
|
- name: Merge lint reports
|
||||||
run: jq -s '[.[]]|flatten' lint-results/*.json &> lint-results/eslint_report.json
|
run: jq -s '[.[]]|flatten' lint-results/*.json &> lint-results/eslint_report.json
|
||||||
|
|
||||||
- name: Annotate Code Linting Results
|
|
||||||
uses: ataylorme/eslint-annotate-action@v2
|
|
||||||
with:
|
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
report-json: "lint-results/eslint_report.json"
|
|
||||||
only-pr-files: false
|
|
||||||
|
|
||||||
- name: Upload ESLint report
|
- name: Upload ESLint report
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# https://playwright.dev/docs/test-sharding#merging-reports-from-multiple-shards
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
jobs:
|
||||||
|
merge-reports:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.github/actions/dangerous-git-checkout
|
||||||
|
- uses: ./.github/actions/yarn-install
|
||||||
|
- uses: ./.github/actions/yarn-playwright-install
|
||||||
|
- name: Download blob reports from GitHub Actions Artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: all-blob-reports
|
||||||
|
pattern: blob-report-*
|
||||||
|
merge-multiple: true
|
||||||
|
- name: Merge into HTML Report
|
||||||
|
run: yarn playwright merge-reports --reporter html ./all-blob-reports
|
||||||
|
- name: Upload HTML report
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: html-report--attempt-${{ github.run_number }}-${{ github.run_attempt }}
|
||||||
|
path: playwright-report
|
||||||
|
retention-days: 14
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
name: "Next.js Bundle Analysis Annotation"
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
annotate:
|
||||||
|
if: always()
|
||||||
|
runs-on: buildjet-2vcpu-ubuntu-2204
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.github/actions/yarn-install
|
||||||
|
- uses: ./.github/actions/cache-build
|
||||||
|
- name: Download base branch bundle stats
|
||||||
|
uses: dawidd6/action-download-artifact@v2
|
||||||
|
if: success()
|
||||||
|
with:
|
||||||
|
workflow: nextjs-bundle-analysis.yml
|
||||||
|
branch: ${{ github.event.pull_request.base.ref }}
|
||||||
|
path: apps/web/.next/analyze/base
|
||||||
|
|
||||||
|
# And here's the second place - this runs after we have both the current and
|
||||||
|
# base branch bundle stats, and will compare them to determine what changed.
|
||||||
|
# There are two configurable arguments that come from package.json:
|
||||||
|
#
|
||||||
|
# - budget: optional, set a budget (bytes) against which size changes are measured
|
||||||
|
# it's set to 350kb here by default, as informed by the following piece:
|
||||||
|
# https://infrequently.org/2021/03/the-performance-inequality-gap/
|
||||||
|
#
|
||||||
|
# - red-status-percentage: sets the percent size increase where you get a red
|
||||||
|
# status indicator, defaults to 20%
|
||||||
|
#
|
||||||
|
# Either of these arguments can be changed or removed by editing the `nextBundleAnalysis`
|
||||||
|
# entry in your package.json file.
|
||||||
|
|
||||||
|
- name: Compare with base branch bundle
|
||||||
|
if: success()
|
||||||
|
run: |
|
||||||
|
cd apps/web
|
||||||
|
ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare
|
||||||
|
|
||||||
|
- name: Get comment body
|
||||||
|
id: get-comment-body
|
||||||
|
if: success() && github.event.number
|
||||||
|
run: |
|
||||||
|
cd apps/web
|
||||||
|
body=$(cat .next/analyze/__bundle_analysis_comment.txt)
|
||||||
|
body="${body//'%'/'%25'}"
|
||||||
|
body="${body//$'\n'/'%0A'}"
|
||||||
|
body="${body//$'\r'/'%0D'}"
|
||||||
|
echo ::set-output name=body::$body
|
||||||
|
|
||||||
|
- name: Find Comment
|
||||||
|
uses: peter-evans/find-comment@v2
|
||||||
|
if: success() && github.event.number
|
||||||
|
id: fc
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.number }}
|
||||||
|
body-includes: "<!-- __NEXTJS_BUNDLE_@calcom/web -->"
|
||||||
|
|
||||||
|
- name: Create Comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v3
|
||||||
|
if: success() && github.event.number && steps.fc.outputs.comment-id == 0
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.number }}
|
||||||
|
body: ${{ steps.get-comment-body.outputs.body }}
|
||||||
|
|
||||||
|
- name: Update Comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v3
|
||||||
|
if: success() && github.event.number && steps.fc.outputs.comment-id != 0
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.number }}
|
||||||
|
body: ${{ steps.get-comment-body.outputs.body }}
|
||||||
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||||
|
edit-mode: replace
|
||||||
@@ -7,6 +7,10 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
|
|
||||||
env:
|
env:
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }}
|
CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }}
|
||||||
@@ -63,65 +67,3 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: bundle
|
name: bundle
|
||||||
path: apps/web/.next/analyze/__bundle_analysis.json
|
path: apps/web/.next/analyze/__bundle_analysis.json
|
||||||
|
|
||||||
- name: Download base branch bundle stats
|
|
||||||
uses: dawidd6/action-download-artifact@v2
|
|
||||||
if: success()
|
|
||||||
with:
|
|
||||||
workflow: nextjs-bundle-analysis.yml
|
|
||||||
branch: ${{ github.event.pull_request.base.ref }}
|
|
||||||
path: apps/web/.next/analyze/base
|
|
||||||
|
|
||||||
# And here's the second place - this runs after we have both the current and
|
|
||||||
# base branch bundle stats, and will compare them to determine what changed.
|
|
||||||
# There are two configurable arguments that come from package.json:
|
|
||||||
#
|
|
||||||
# - budget: optional, set a budget (bytes) against which size changes are measured
|
|
||||||
# it's set to 350kb here by default, as informed by the following piece:
|
|
||||||
# https://infrequently.org/2021/03/the-performance-inequality-gap/
|
|
||||||
#
|
|
||||||
# - red-status-percentage: sets the percent size increase where you get a red
|
|
||||||
# status indicator, defaults to 20%
|
|
||||||
#
|
|
||||||
# Either of these arguments can be changed or removed by editing the `nextBundleAnalysis`
|
|
||||||
# entry in your package.json file.
|
|
||||||
- name: Compare with base branch bundle
|
|
||||||
if: success()
|
|
||||||
run: |
|
|
||||||
cd apps/web
|
|
||||||
ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare
|
|
||||||
|
|
||||||
- name: Get comment body
|
|
||||||
id: get-comment-body
|
|
||||||
if: success() && github.event.number
|
|
||||||
run: |
|
|
||||||
cd apps/web
|
|
||||||
body=$(cat .next/analyze/__bundle_analysis_comment.txt)
|
|
||||||
body="${body//'%'/'%25'}"
|
|
||||||
body="${body//$'\n'/'%0A'}"
|
|
||||||
body="${body//$'\r'/'%0D'}"
|
|
||||||
echo ::set-output name=body::$body
|
|
||||||
|
|
||||||
- name: Find Comment
|
|
||||||
uses: peter-evans/find-comment@v2
|
|
||||||
if: success() && github.event.number
|
|
||||||
id: fc
|
|
||||||
with:
|
|
||||||
issue-number: ${{ github.event.number }}
|
|
||||||
body-includes: "<!-- __NEXTJS_BUNDLE_@calcom/web -->"
|
|
||||||
|
|
||||||
- name: Create Comment
|
|
||||||
uses: peter-evans/create-or-update-comment@v3
|
|
||||||
if: success() && github.event.number && steps.fc.outputs.comment-id == 0
|
|
||||||
with:
|
|
||||||
issue-number: ${{ github.event.number }}
|
|
||||||
body: ${{ steps.get-comment-body.outputs.body }}
|
|
||||||
|
|
||||||
- name: Update Comment
|
|
||||||
uses: peter-evans/create-or-update-comment@v3
|
|
||||||
if: success() && github.event.number && steps.fc.outputs.comment-id != 0
|
|
||||||
with:
|
|
||||||
issue-number: ${{ github.event.number }}
|
|
||||||
body: ${{ steps.get-comment-body.outputs.body }}
|
|
||||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
|
||||||
edit-mode: replace
|
|
||||||
@@ -7,11 +7,14 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
label-pr:
|
label-pr:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Label PR as ready for E2E
|
- name: Label PR as ready for E2E
|
||||||
if: github.event.review.state == 'approved'
|
if: github.event.review.state == 'approved'
|
||||||
uses: actions-ecosystem/action-add-labels@v1
|
uses: actions-ecosystem/action-add-labels@v1
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.READY_FOR_E2E_PAT }}
|
||||||
labels: 'ready-for-e2e'
|
labels: 'ready-for-e2e'
|
||||||
@@ -8,6 +8,10 @@ on:
|
|||||||
- gh-actions-test-branch
|
- gh-actions-test-branch
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
contents: read
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
@@ -39,6 +43,8 @@ jobs:
|
|||||||
needs: [changes]
|
needs: [changes]
|
||||||
runs-on: buildjet-2vcpu-ubuntu-2204
|
runs-on: buildjet-2vcpu-ubuntu-2204
|
||||||
name: Check for E2E label
|
name: Check for E2E label
|
||||||
|
permissions:
|
||||||
|
pull-requests: read
|
||||||
outputs:
|
outputs:
|
||||||
run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'ready-for-e2e')) }}
|
run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'ready-for-e2e')) }}
|
||||||
steps:
|
steps:
|
||||||
@@ -85,44 +91,50 @@ jobs:
|
|||||||
console.log('Found the label?', labelFound);
|
console.log('Found the label?', labelFound);
|
||||||
core.setOutput('run-e2e', labelFound);
|
core.setOutput('run-e2e', labelFound);
|
||||||
|
|
||||||
|
deps:
|
||||||
|
name: Install dependencies
|
||||||
|
needs: [changes, check-label]
|
||||||
|
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
|
uses: ./.github/workflows/yarn-install.yml
|
||||||
|
|
||||||
type-check:
|
type-check:
|
||||||
name: Type check
|
name: Type check
|
||||||
needs: [changes, check-label]
|
needs: [changes, check-label, deps]
|
||||||
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
uses: ./.github/workflows/check-types.yml
|
uses: ./.github/workflows/check-types.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
name: Linters
|
name: Linters
|
||||||
needs: [changes, check-label]
|
needs: [changes, check-label, deps]
|
||||||
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
uses: ./.github/workflows/lint.yml
|
uses: ./.github/workflows/lint.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
unit-test:
|
unit-test:
|
||||||
name: Tests
|
name: Tests
|
||||||
needs: [changes, check-label]
|
needs: [changes, check-label, deps]
|
||||||
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
uses: ./.github/workflows/unit-tests.yml
|
uses: ./.github/workflows/unit-tests.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
build-api-v1:
|
build-api-v1:
|
||||||
name: Production builds
|
name: Production builds
|
||||||
needs: [changes, check-label]
|
needs: [changes, check-label, deps]
|
||||||
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
uses: ./.github/workflows/api-v1-production-build.yml
|
uses: ./.github/workflows/api-v1-production-build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
build-api-v2:
|
build-api-v2:
|
||||||
name: Production builds
|
name: Production builds
|
||||||
needs: [changes, check-label]
|
needs: [changes, check-label, deps]
|
||||||
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
uses: ./.github/workflows/api-v2-production-build.yml
|
uses: ./.github/workflows/api-v2-production-build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Production builds
|
name: Production builds
|
||||||
needs: [changes, check-label]
|
needs: [changes, check-label, deps]
|
||||||
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
uses: ./.github/workflows/production-build-without-database.yml
|
uses: ./.github/workflows/production-build-without-database.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
@@ -141,6 +153,13 @@ jobs:
|
|||||||
uses: ./.github/workflows/e2e.yml
|
uses: ./.github/workflows/e2e.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
|
e2e-api-v2:
|
||||||
|
name: Tests
|
||||||
|
needs: [changes, check-label, build, build-api-v1, build-api-v2]
|
||||||
|
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
|
uses: ./.github/workflows/e2e-api-v2.yml
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
e2e-app-store:
|
e2e-app-store:
|
||||||
name: Tests
|
name: Tests
|
||||||
needs: [changes, check-label, build, build-api-v1, build-api-v2]
|
needs: [changes, check-label, build, build-api-v1, build-api-v2]
|
||||||
@@ -168,8 +187,42 @@ jobs:
|
|||||||
uses: ./.github/workflows/nextjs-bundle-analysis.yml
|
uses: ./.github/workflows/nextjs-bundle-analysis.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|
||||||
|
merge-reports:
|
||||||
|
name: Merge reports
|
||||||
|
if: ${{ !cancelled() && needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
|
needs: [changes, check-label, e2e, e2e-embed, e2e-embed-react, e2e-app-store]
|
||||||
|
uses: ./.github/workflows/merge-reports.yml
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
publish-report:
|
||||||
|
name: Publish HTML report
|
||||||
|
if: ${{ !cancelled() && needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
needs: [changes, check-label, merge-reports]
|
||||||
|
uses: ./.github/workflows/publish-report.yml
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
required:
|
required:
|
||||||
needs: [changes, lint, type-check, unit-test, integration-test, check-label, build, build-api-v1, build-api-v2, e2e, e2e-embed, e2e-embed-react, e2e-app-store]
|
needs:
|
||||||
|
[
|
||||||
|
changes,
|
||||||
|
lint,
|
||||||
|
type-check,
|
||||||
|
unit-test,
|
||||||
|
integration-test,
|
||||||
|
check-label,
|
||||||
|
build,
|
||||||
|
build-api-v1,
|
||||||
|
build-api-v2,
|
||||||
|
e2e,
|
||||||
|
e2e-api-v2,
|
||||||
|
e2e-embed,
|
||||||
|
e2e-embed-react,
|
||||||
|
e2e-app-store,
|
||||||
|
]
|
||||||
if: always()
|
if: always()
|
||||||
runs-on: buildjet-2vcpu-ubuntu-2204
|
runs-on: buildjet-2vcpu-ubuntu-2204
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
name: Pre-release checks
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
changes:
|
|
||||||
name: Detect changes
|
|
||||||
runs-on: buildjet-4vcpu-ubuntu-2204
|
|
||||||
permissions:
|
|
||||||
pull-requests: read
|
|
||||||
outputs:
|
|
||||||
app-store: ${{ steps.filter.outputs.app-store }}
|
|
||||||
embed: ${{ steps.filter.outputs.embed }}
|
|
||||||
embed-react: ${{ steps.filter.outputs.embed-react }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: ./.github/actions/dangerous-git-checkout
|
|
||||||
- uses: dorny/paths-filter@v3
|
|
||||||
id: filter
|
|
||||||
with:
|
|
||||||
filters: |
|
|
||||||
app-store:
|
|
||||||
- 'apps/web/**'
|
|
||||||
- 'packages/app-store/**'
|
|
||||||
- 'playwright.config.ts'
|
|
||||||
embed:
|
|
||||||
- 'apps/web/**'
|
|
||||||
- 'packages/embeds/**'
|
|
||||||
- 'playwright.config.ts'
|
|
||||||
embed-react:
|
|
||||||
- 'apps/web/**'
|
|
||||||
- 'packages/embeds/**'
|
|
||||||
- 'playwright.config.ts'
|
|
||||||
|
|
||||||
lint:
|
|
||||||
name: Linters
|
|
||||||
uses: ./.github/workflows/lint.yml
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
build:
|
|
||||||
name: Production builds
|
|
||||||
uses: ./.github/workflows/production-build-without-database.yml
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
e2e:
|
|
||||||
name: E2E tests
|
|
||||||
needs: [changes, lint, build]
|
|
||||||
uses: ./.github/workflows/e2e.yml
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
e2e-app-store:
|
|
||||||
name: E2E App Store tests
|
|
||||||
needs: [changes, lint, build]
|
|
||||||
uses: ./.github/workflows/e2e-app-store.yml
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
e2e-embed:
|
|
||||||
name: E2E embeds tests
|
|
||||||
needs: [changes, lint, build]
|
|
||||||
uses: ./.github/workflows/e2e-embed.yml
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
e2e-embed-react:
|
|
||||||
name: E2E React embeds tests
|
|
||||||
needs: [changes, lint, build]
|
|
||||||
uses: ./.github/workflows/e2e-embed-react.yml
|
|
||||||
secrets: inherit
|
|
||||||
|
|
||||||
required:
|
|
||||||
needs: [changes, lint, build, e2e, e2e-app-store, e2e-embed, e2e-embed-react]
|
|
||||||
if: always()
|
|
||||||
runs-on: buildjet-2vcpu-ubuntu-2204
|
|
||||||
steps:
|
|
||||||
- name: fail if conditional jobs failed
|
|
||||||
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'skipped') || contains(needs.*.result, 'cancelled')
|
|
||||||
run: exit 1
|
|
||||||
@@ -2,6 +2,9 @@ name: Production Builds
|
|||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
env:
|
env:
|
||||||
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
ALLOWED_HOSTNAMES: ${{ vars.CI_ALLOWED_HOSTNAMES }}
|
||||||
CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }}
|
CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
jobs:
|
||||||
|
publish-report:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
# Unique URL path for each workflow run attempt
|
||||||
|
HTML_REPORT_URL_PATH: reports/${{ github.head_ref }}/${{ github.run_id }}/${{ github.run_attempt }}
|
||||||
|
BRANCH_REPORTS_DIR: reports/${{ github.head_ref }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout GitHub Pages Branch
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: gh-pages
|
||||||
|
- name: Set Git User
|
||||||
|
# see: https://github.com/actions/checkout/issues/13#issuecomment-724415212
|
||||||
|
run: |
|
||||||
|
git config --global user.name "github-actions[bot]"
|
||||||
|
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
- name: Check for workflow reports
|
||||||
|
run: |
|
||||||
|
if [ -z "$(ls -A $BRANCH_REPORTS_DIR)" ]; then
|
||||||
|
echo "BRANCH_REPORTS_EXIST="false"" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "BRANCH_REPORTS_EXIST="true"" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
- name: Cleanup old HTML reports
|
||||||
|
if: ${{ env.BRANCH_REPORTS_EXIST == 'true' }}
|
||||||
|
timeout-minutes: 3
|
||||||
|
run: |
|
||||||
|
rm -rf $BRANCH_REPORTS_DIR
|
||||||
|
git add .
|
||||||
|
git commit -m "workflow: remove all reports for branch ${{ github.head_ref }}"
|
||||||
|
- name: Download zipped HTML report
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: html-report--attempt-${{ github.run_number }}-${{ github.run_attempt }}
|
||||||
|
path: ${{ env.HTML_REPORT_URL_PATH }}
|
||||||
|
- name: Push HTML Report
|
||||||
|
timeout-minutes: 3
|
||||||
|
# commit report, then try push-rebase-loop until it's able to merge the HTML report to the gh-pages branch
|
||||||
|
# this is necessary when this job running at least twice at the same time (e.g. through two pushes at the same time)
|
||||||
|
run: |
|
||||||
|
git add .
|
||||||
|
git commit -m "workflow: add HTML report for run-id ${{ github.run_id }} (attempt: ${{ github.run_attempt }})"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
git pull --rebase
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to rebase. Please review manually."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
git push
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Successfully pushed HTML report to repo."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
- name: Output Report URL as Workflow Annotation
|
||||||
|
id: url
|
||||||
|
run: |
|
||||||
|
FULL_HTML_REPORT_URL=https://calcom.github.io/cal.com/$HTML_REPORT_URL_PATH
|
||||||
|
echo "::notice title=📋 Published Playwright Test Report::$FULL_HTML_REPORT_URL"
|
||||||
|
echo "link=$FULL_HTML_REPORT_URL" >> $GITHUB_OUTPUT
|
||||||
|
- name: Find Comment
|
||||||
|
uses: peter-evans/find-comment@v2
|
||||||
|
id: fc
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
comment-author: "github-actions[bot]"
|
||||||
|
body-includes: <!-- GENERATED-E2E-RESULTS -->
|
||||||
|
- name: Create comment
|
||||||
|
if: steps.fc.outputs.comment-id == ''
|
||||||
|
uses: peter-evans/create-or-update-comment@v3
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
body: |
|
||||||
|
<!-- GENERATED-E2E-RESULTS -->
|
||||||
|
## E2E results are ready!
|
||||||
|
- [Workflow #${{ github.run_number }}.${{ github.run_attempt }} latest results](${{ steps.url.outputs.link }})
|
||||||
|
- name: Update comment
|
||||||
|
if: steps.fc.outputs.comment-id != ''
|
||||||
|
uses: peter-evans/create-or-update-comment@v3
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||||
|
edit-mode: replace
|
||||||
|
body: |
|
||||||
|
<!-- GENERATED-E2E-RESULTS -->
|
||||||
|
## E2E results are ready!
|
||||||
|
- [Workflow #${{ github.run_number }}.${{ github.run_attempt }} latest results](${{ steps.url.outputs.link }})
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
name: Unit
|
name: Unit
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
workflow_run:
|
permissions:
|
||||||
workflows: [Crowdin Action]
|
contents: read
|
||||||
types: [completed]
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Unit
|
name: Unit
|
||||||
@@ -13,7 +12,11 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: ./.github/actions/dangerous-git-checkout
|
- uses: ./.github/actions/dangerous-git-checkout
|
||||||
- uses: ./.github/actions/yarn-install
|
- uses: ./.github/actions/yarn-install
|
||||||
# Should be an 8GB machine as per https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
|
|
||||||
- run: yarn test
|
- run: yarn test
|
||||||
# We could add different timezones here that we need to run our tests in
|
# We could add different timezones here that we need to run our tests in
|
||||||
- run: TZ=America/Los_Angeles yarn test -- --timeZoneDependentTestsOnly
|
- run: TZ=America/Los_Angeles yarn test -- --timeZoneDependentTestsOnly
|
||||||
|
- name: Run API v2 tests
|
||||||
|
working-directory: apps/api/v2
|
||||||
|
run: |
|
||||||
|
export NODE_OPTIONS="--max_old_space_size=8192"
|
||||||
|
yarn test
|
||||||
@@ -3,6 +3,9 @@ name: Yarn install
|
|||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
setup:
|
setup:
|
||||||
name: Yarn install & cache
|
name: Yarn install & cache
|
||||||
@@ -12,3 +15,4 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: ./.github/actions/dangerous-git-checkout
|
- uses: ./.github/actions/dangerous-git-checkout
|
||||||
- uses: ./.github/actions/yarn-install
|
- uses: ./.github/actions/yarn-install
|
||||||
|
- uses: ./.github/actions/yarn-playwright-install
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<a href="https://cal.com"><strong>Learn more »</strong></a>
|
<a href="https://cal.com"><strong>Learn more »</strong></a>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<a href="https://go.cal.com/discord">Discord</a>
|
<a href="https://github.com/calcom/cal.com/discussions">Discussions</a>
|
||||||
·
|
·
|
||||||
<a href="https://cal.com">Website</a>
|
<a href="https://cal.com">Website</a>
|
||||||
·
|
·
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://go.cal.com/discord"><img src="https://img.shields.io/badge/Discord-go.cal.com%2Fdiscord-%234A154B" alt="Join Cal.com Discord"></a>
|
|
||||||
<a href="https://www.producthunt.com/products/cal-com"><img src="https://img.shields.io/badge/Product%20Hunt-%231%20Product%20of%20the%20Month-%23DA552E" alt="Product Hunt"></a>
|
<a href="https://www.producthunt.com/products/cal-com"><img src="https://img.shields.io/badge/Product%20Hunt-%231%20Product%20of%20the%20Month-%23DA552E" alt="Product Hunt"></a>
|
||||||
<a href="https://status.cal.com"><img height="20px" src="https://betteruptime.com/status-badges/v1/monitor/a9kf.svg" alt="Uptime"></a>
|
<a href="https://status.cal.com"><img height="20px" src="https://betteruptime.com/status-badges/v1/monitor/a9kf.svg" alt="Uptime"></a>
|
||||||
<a href="https://github.com/calcom/cal.com/stargazers"><img src="https://img.shields.io/github/stars/calcom/cal.com" alt="Github Stars"></a>
|
<a href="https://github.com/calcom/cal.com/stargazers"><img src="https://img.shields.io/github/stars/calcom/cal.com" alt="Github Stars"></a>
|
||||||
@@ -37,7 +36,6 @@
|
|||||||
<a href="https://twitch.tv/calcomtv"><img src="https://img.shields.io/twitch/status/calcomtv?style=flat"></a>
|
<a href="https://twitch.tv/calcomtv"><img src="https://img.shields.io/twitch/status/calcomtv?style=flat"></a>
|
||||||
<a href="https://github.com/calcom/cal.com/issues?q=is:issue+is:open+label:%22%F0%9F%99%8B%F0%9F%8F%BB%E2%80%8D%E2%99%82%EF%B8%8Fhelp+wanted%22"><img src="https://img.shields.io/badge/Help%20Wanted-Contribute-blue"></a>
|
<a href="https://github.com/calcom/cal.com/issues?q=is:issue+is:open+label:%22%F0%9F%99%8B%F0%9F%8F%BB%E2%80%8D%E2%99%82%EF%B8%8Fhelp+wanted%22"><img src="https://img.shields.io/badge/Help%20Wanted-Contribute-blue"></a>
|
||||||
<a href="https://cal.com/figma"><img src="https://img.shields.io/badge/Figma-Design%20System-blueviolet"></a>
|
<a href="https://cal.com/figma"><img src="https://img.shields.io/badge/Figma-Design%20System-blueviolet"></a>
|
||||||
<a href="https://discord.com/channels/1125390093386010654/1125398231585661040"><img src="https://img.shields.io/badge/translations-contribute-brightgreen" /></a>
|
|
||||||
<a href="https://contributor-covenant.org/version/1/4/code-of-conduct/ "><img src="https://img.shields.io/badge/Contributor%20Covenant-1.4-purple" /></a>
|
<a href="https://contributor-covenant.org/version/1/4/code-of-conduct/ "><img src="https://img.shields.io/badge/Contributor%20Covenant-1.4-purple" /></a>
|
||||||
<a href="https://console.algora.io/org/cal/bounties?status=open"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fconsole.algora.io%2Fapi%2Fshields%2Fcal%2Fbounties%3Fstatus%3Dopen" /></a>
|
<a href="https://console.algora.io/org/cal/bounties?status=open"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fconsole.algora.io%2Fapi%2Fshields%2Fcal%2Fbounties%3Fstatus%3Dopen" /></a>
|
||||||
</p>
|
</p>
|
||||||
@@ -382,7 +380,7 @@ Currently Vercel Pro Plan is required to be able to Deploy this application with
|
|||||||
|
|
||||||
### Elestio
|
### Elestio
|
||||||
|
|
||||||
[](https://elest.io/open-source/cal.com)
|
[](https://elest.io/open-source/cal.com)
|
||||||
|
|
||||||
<!-- ROADMAP -->
|
<!-- ROADMAP -->
|
||||||
|
|
||||||
@@ -461,7 +459,7 @@ We have a list of [help wanted](https://github.com/calcom/cal.com/issues?q=is:is
|
|||||||
|
|
||||||
### Translations
|
### Translations
|
||||||
|
|
||||||
Don't code but still want to contribute? Join our [discord](https://go.cal.com/discord) and join the [#Translate channel](https://discord.com/channels/1125390093386010654/1125398231585661040) and let us know what language you want to translate.
|
Don't code but still want to contribute? Join our [Discussions](https://github.com/calcom/cal.com/discussions) and join the [#Translate channel](https://github.com/calcom/cal.com/discussions/categories/translations) and let us know what language you want to translate.
|
||||||
|
|
||||||
                                             {
|
|||||||
|
|
||||||
// This verifies the apiKey and sets the user if it is valid.
|
// This verifies the apiKey and sets the user if it is valid.
|
||||||
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
||||||
const hasValidLicense = await checkLicense(prisma);
|
const licenseKeyService = await LicenseKeySingleton.getInstance();
|
||||||
if (!hasValidLicense && IS_PRODUCTION)
|
const hasValidLicense = await licenseKeyService.checkLicense();
|
||||||
|
|
||||||
|
if (!hasValidLicense && IS_PRODUCTION) {
|
||||||
return res.status(401).json({ error: "Invalid or missing CALCOM_LICENSE_KEY environment variable" });
|
return res.status(401).json({ error: "Invalid or missing CALCOM_LICENSE_KEY environment variable" });
|
||||||
|
}
|
||||||
// Check if the apiKey query param is provided.
|
// Check if the apiKey query param is provided.
|
||||||
if (!req.query.apiKey) return res.status(401).json({ message: "No apiKey provided" });
|
if (!req.query.apiKey) return res.status(401).json({ message: "No apiKey provided" });
|
||||||
// remove the prefix from the user provided api_key. If no env set default to "cal_"
|
// remove the prefix from the user provided api_key. If no env set default to "cal_"
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ export const isAdminGuard = async (req: NextApiRequest) => {
|
|||||||
accepted: true,
|
accepted: true,
|
||||||
team: {
|
team: {
|
||||||
isOrganization: true,
|
isOrganization: true,
|
||||||
|
organizationSettings: {
|
||||||
|
isAdminAPIEnabled: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OR: [{ role: MembershipRole.OWNER }, { role: MembershipRole.ADMIN }],
|
OR: [{ role: MembershipRole.OWNER }, { role: MembershipRole.ADMIN }],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { _BookingModel as Booking, _AttendeeModel, _UserModel, _PaymentModel } from "@calcom/prisma/zod";
|
import { _AttendeeModel, _BookingModel as Booking, _PaymentModel, _UserModel } from "@calcom/prisma/zod";
|
||||||
import { extendedBookingCreateBody, iso8601 } from "@calcom/prisma/zod-utils";
|
import { extendedBookingCreateBody, iso8601 } from "@calcom/prisma/zod-utils";
|
||||||
|
|
||||||
import { schemaQueryUserId } from "./shared/queryUserId";
|
import { schemaQueryUserId } from "./shared/queryUserId";
|
||||||
@@ -23,8 +23,11 @@ export const schemaBookingGetParams = z.object({
|
|||||||
dateTo: iso8601.optional(),
|
dateTo: iso8601.optional(),
|
||||||
order: z.enum(["asc", "desc"]).default("asc"),
|
order: z.enum(["asc", "desc"]).default("asc"),
|
||||||
sortBy: z.enum(["createdAt", "updatedAt"]).optional(),
|
sortBy: z.enum(["createdAt", "updatedAt"]).optional(),
|
||||||
|
status: z.enum(["upcoming"]).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type Status = z.infer<typeof schemaBookingGetParams>["status"];
|
||||||
|
|
||||||
const schemaBookingEditParams = z
|
const schemaBookingEditParams = z
|
||||||
.object({
|
.object({
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import { _PaymentModel as Payment } from "@calcom/prisma/zod";
|
import { _PaymentModel as Payment } from "@calcom/prisma/zod";
|
||||||
|
|
||||||
// FIXME: Payment seems a delicate endpoint, do we need to remove anything here?
|
export const schemaPaymentPublic = Payment.pick({
|
||||||
export const schemaPaymentBodyParams = Payment.omit({ id: true });
|
id: true,
|
||||||
export const schemaPaymentPublic = Payment.omit({ externalId: true });
|
amount: true,
|
||||||
|
success: true,
|
||||||
|
refunded: true,
|
||||||
|
fee: true,
|
||||||
|
paymentOption: true,
|
||||||
|
currency: true,
|
||||||
|
bookingId: true,
|
||||||
|
});
|
||||||
@@ -9,6 +9,7 @@ export const schemaTeamBaseBodyParams = Team.omit({ id: true, createdAt: true })
|
|||||||
isOrganization: true,
|
isOrganization: true,
|
||||||
isPlatform: true,
|
isPlatform: true,
|
||||||
smsLockState: true,
|
smsLockState: true,
|
||||||
|
smsLockReviewedByAdmin: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const schemaTeamRequiredParams = z.object({
|
const schemaTeamRequiredParams = z.object({
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
|||||||
* tags:
|
* tags:
|
||||||
* - availabilities
|
* - availabilities
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/availability
|
* url: https://docs.cal.com/docs/core-features/availability
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, availability removed successfully
|
* description: OK, availability removed successfully
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
|||||||
* tags:
|
* tags:
|
||||||
* - availabilities
|
* - availabilities
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/availability
|
* url: https://docs.cal.com/docs/core-features/availability
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* description: OK
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
|||||||
* tags:
|
* tags:
|
||||||
* - availabilities
|
* - availabilities
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/availability
|
* url: https://docs.cal.com/docs/core-features/availability
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, availability edited successfully
|
* description: OK, availability edited successfully
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ import {
|
|||||||
* tags:
|
* tags:
|
||||||
* - availabilities
|
* - availabilities
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/availability
|
* url: https://docs.cal.com/docs/core-features/availability
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, availability created
|
* description: OK, availability created
|
||||||
|
|||||||
@@ -63,6 +63,25 @@ import { schemaQuerySingleOrMultipleUserIds } from "~/lib/validations/shared/que
|
|||||||
* schema:
|
* schema:
|
||||||
* type: string
|
* type: string
|
||||||
* enum: [createdAt, updatedAt]
|
* enum: [createdAt, updatedAt]
|
||||||
|
* - in: query
|
||||||
|
* name: status
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* enum: [upcoming]
|
||||||
|
* description: Filter bookings by status, it will overwrite dateFrom and dateTo filters
|
||||||
|
* - in: query
|
||||||
|
* name: dateFrom
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* description: ISO 8601 date string to filter bookings by start time
|
||||||
|
* - in: query
|
||||||
|
* name: dateTo
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* description: ISO 8601 date string to filter bookings by end time
|
||||||
* operationId: listBookings
|
* operationId: listBookings
|
||||||
* tags:
|
* tags:
|
||||||
* - bookings
|
* - bookings
|
||||||
@@ -130,6 +149,7 @@ type GetAdminArgsType = {
|
|||||||
requestedUserIds: number[];
|
requestedUserIds: number[];
|
||||||
userId: number;
|
userId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the WHERE clause for Prisma booking findMany operation.
|
* Constructs the WHERE clause for Prisma booking findMany operation.
|
||||||
*
|
*
|
||||||
@@ -148,7 +168,9 @@ function buildWhereClause(
|
|||||||
) {
|
) {
|
||||||
const filterByAttendeeEmails = attendeeEmails.length > 0;
|
const filterByAttendeeEmails = attendeeEmails.length > 0;
|
||||||
const userFilter = userIds.length > 0 ? { userId: { in: userIds } } : !!userId ? { userId } : {};
|
const userFilter = userIds.length > 0 ? { userId: { in: userIds } } : !!userId ? { userId } : {};
|
||||||
|
|
||||||
let whereClause = {};
|
let whereClause = {};
|
||||||
|
|
||||||
if (filterByAttendeeEmails) {
|
if (filterByAttendeeEmails) {
|
||||||
whereClause = {
|
whereClause = {
|
||||||
AND: [
|
AND: [
|
||||||
@@ -177,9 +199,7 @@ function buildWhereClause(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return whereClause;
|
||||||
...whereClause,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handler(req: NextApiRequest) {
|
export async function handler(req: NextApiRequest) {
|
||||||
@@ -189,7 +209,7 @@ export async function handler(req: NextApiRequest) {
|
|||||||
isOrganizationOwnerOrAdmin,
|
isOrganizationOwnerOrAdmin,
|
||||||
pagination: { take, skip },
|
pagination: { take, skip },
|
||||||
} = req;
|
} = req;
|
||||||
const { dateFrom, dateTo, order, sortBy } = schemaBookingGetParams.parse(req.query);
|
const { dateFrom, dateTo, order, sortBy, status } = schemaBookingGetParams.parse(req.query);
|
||||||
|
|
||||||
const args: Prisma.BookingFindManyArgs = {};
|
const args: Prisma.BookingFindManyArgs = {};
|
||||||
if (req.query.take && req.query.page) {
|
if (req.query.take && req.query.page) {
|
||||||
@@ -275,6 +295,19 @@ export async function handler(req: NextApiRequest) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
switch (status) {
|
||||||
|
case "upcoming":
|
||||||
|
args.where = {
|
||||||
|
...args.where,
|
||||||
|
startTime: { gte: new Date().toISOString() },
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new HttpError({ message: "Invalid status", statusCode: 400 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.booking.findMany(args);
|
const data = await prisma.booking.findMany(args);
|
||||||
return { bookings: data.map((booking) => schemaBookingReadPublic.parse(booking)) };
|
return { bookings: data.map((booking) => schemaBookingReadPublic.parse(booking)) };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ import { getAccessibleUsers } from "~/lib/utils/retrieveScopedAccessibleUsers";
|
|||||||
* type: string
|
* type: string
|
||||||
* format: date-time
|
* format: date-time
|
||||||
* description: 'End time of the Event'
|
* description: 'End time of the Event'
|
||||||
|
* rescheduleUid:
|
||||||
|
* type: string
|
||||||
|
* format: UID
|
||||||
|
* description: 'Uid of the booking to reschedule'
|
||||||
* responses:
|
* responses:
|
||||||
* type: object
|
* type: object
|
||||||
* required:
|
* required:
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ const swaggerHandler = withSwagger({
|
|||||||
{ url: "https://api.cal.com/v1" },
|
{ url: "https://api.cal.com/v1" },
|
||||||
],
|
],
|
||||||
externalDocs: {
|
externalDocs: {
|
||||||
url: "https://docs.cal.com",
|
url: "https://docs.cal.com/docs",
|
||||||
description: "Find more info at our main docs: https://docs.cal.com/",
|
description: "Find more info at our main docs: https://docs.cal.com/docs/",
|
||||||
},
|
},
|
||||||
info: {
|
info: {
|
||||||
title: `${pjson.name}: ${pjson.description}`,
|
title: `${pjson.name}: ${pjson.description}`,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
|
|||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/event-types
|
* url: https://docs.cal.com/docs/core-features/event-types
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, eventType removed successfully
|
* description: OK, eventType removed successfully
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import getCalLink from "../_utils/getCalLink";
|
|||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/event-types
|
* url: https://docs.cal.com/docs/core-features/event-types
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* description: OK
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ import checkTeamEventEditPermission from "../_utils/checkTeamEventEditPermission
|
|||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/event-types
|
* url: https://docs.cal.com/docs/core-features/event-types
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, eventType edited successfully
|
* description: OK, eventType edited successfully
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import getCalLink from "./_utils/getCalLink";
|
|||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/event-types
|
* url: https://docs.cal.com/docs/core-features/event-types
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* description: OK
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ import ensureOnlyMembersAsHosts from "./_utils/ensureOnlyMembersAsHosts";
|
|||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/event-types
|
* url: https://docs.cal.com/docs/core-features/event-types
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, event type created
|
* description: OK, event type created
|
||||||
@@ -278,8 +278,8 @@ async function postHandler(req: NextApiRequest) {
|
|||||||
|
|
||||||
let data: Prisma.EventTypeCreateArgs["data"] = {
|
let data: Prisma.EventTypeCreateArgs["data"] = {
|
||||||
...parsedBody,
|
...parsedBody,
|
||||||
userId,
|
userId: !!parsedBody.teamId ? null : userId,
|
||||||
users: { connect: { id: userId } },
|
users: !!parsedBody.teamId ? undefined : { connect: { id: userId } },
|
||||||
bookingLimits: bookingLimits === null ? Prisma.DbNull : bookingLimits,
|
bookingLimits: bookingLimits === null ? Prisma.DbNull : bookingLimits,
|
||||||
durationLimits: durationLimits === null ? Prisma.DbNull : durationLimits,
|
durationLimits: durationLimits === null ? Prisma.DbNull : durationLimits,
|
||||||
};
|
};
|
||||||
@@ -291,7 +291,7 @@ async function postHandler(req: NextApiRequest) {
|
|||||||
await checkUserMembership(req);
|
await checkUserMembership(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSystemWideAdmin && parsedBody.userId) {
|
if (isSystemWideAdmin && parsedBody.userId && !parsedBody.teamId) {
|
||||||
data = { ...parsedBody, users: { connect: { id: parsedBody.userId } } };
|
data = { ...parsedBody, users: { connect: { id: parsedBody.userId } } };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
language: data.language,
|
language: data.language,
|
||||||
teamId: data.teamId,
|
teamId: data.teamId,
|
||||||
usernameOrEmail: data.usernameOrEmail,
|
usernameOrEmail: data.usernameOrEmail,
|
||||||
isOrg: data.isOrg,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { success: true, message: `${data.usernameOrEmail} has been invited.` };
|
return { success: true, message: `${data.usernameOrEmail} has been invited.` };
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ export async function patchHandler(req: NextApiRequest) {
|
|||||||
metadata: NonNullable<typeof data.metadata> | undefined;
|
metadata: NonNullable<typeof data.metadata> | undefined;
|
||||||
} = {
|
} = {
|
||||||
...data,
|
...data,
|
||||||
|
smsLockReviewedByAdmin: false,
|
||||||
metadata: data.metadata === null ? {} : data.metadata || undefined,
|
metadata: data.metadata === null ? {} : data.metadata || undefined,
|
||||||
};
|
};
|
||||||
const team = await prisma.team.update({ where: { id: teamId }, data: cloneData });
|
const team = await prisma.team.update({ where: { id: teamId }, data: cloneData });
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const querySchema = z.object({
|
|||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/event-types
|
* url: https://docs.cal.com/docs/core-features/event-types
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* description: OK
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ import { schemaTeamCreateBodyParams, schemaTeamReadPublic } from "~/lib/validati
|
|||||||
* ownerId:
|
* ownerId:
|
||||||
* type: number
|
* type: number
|
||||||
* description: ID of the team owner - only admins can set this.
|
* description: ID of the team owner - only admins can set this.
|
||||||
|
* parentId:
|
||||||
|
* type: number
|
||||||
|
* description: ID of the parent organization.
|
||||||
* tags:
|
* tags:
|
||||||
* - teams
|
* - teams
|
||||||
* responses:
|
* responses:
|
||||||
@@ -99,7 +102,7 @@ async function postHandler(req: NextApiRequest) {
|
|||||||
if (alreadyExist) throw new HttpError({ statusCode: 409, message: "Team slug already exists" });
|
if (alreadyExist) throw new HttpError({ statusCode: 409, message: "Team slug already exists" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if parentId is related to this user
|
// Check if parentId is related to this user and is an organization
|
||||||
if (data.parentId) {
|
if (data.parentId) {
|
||||||
const parentTeam = await prisma.team.findFirst({
|
const parentTeam = await prisma.team.findFirst({
|
||||||
where: { id: data.parentId, members: { some: { userId, role: { in: ["OWNER", "ADMIN"] } } } },
|
where: { id: data.parentId, members: { some: { userId, role: { in: ["OWNER", "ADMIN"] } } } },
|
||||||
@@ -107,7 +110,13 @@ async function postHandler(req: NextApiRequest) {
|
|||||||
if (!parentTeam)
|
if (!parentTeam)
|
||||||
throw new HttpError({
|
throw new HttpError({
|
||||||
statusCode: 401,
|
statusCode: 401,
|
||||||
message: "Unauthorized: Invalid parent id. You can only use parent id of your own teams.",
|
message: "Unauthorized: Invalid parent id. You can only use parent id if you are org owner or admin.",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (parentTeam.parentId)
|
||||||
|
throw new HttpError({
|
||||||
|
statusCode: 400,
|
||||||
|
message: "parentId must be of an organization, not a team.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,10 +125,11 @@ async function postHandler(req: NextApiRequest) {
|
|||||||
metadata: NonNullable<typeof data.metadata> | undefined;
|
metadata: NonNullable<typeof data.metadata> | undefined;
|
||||||
} = {
|
} = {
|
||||||
...data,
|
...data,
|
||||||
|
smsLockReviewedByAdmin: false,
|
||||||
metadata: data.metadata === null ? {} : data.metadata || undefined,
|
metadata: data.metadata === null ? {} : data.metadata || undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!IS_TEAM_BILLING_ENABLED) {
|
if (!IS_TEAM_BILLING_ENABLED || data.parentId) {
|
||||||
const team = await prisma.team.create({
|
const team = await prisma.team.create({
|
||||||
data: {
|
data: {
|
||||||
...cloneData,
|
...cloneData,
|
||||||
@@ -135,7 +145,7 @@ async function postHandler(req: NextApiRequest) {
|
|||||||
return {
|
return {
|
||||||
team: schemaTeamReadPublic.parse(team),
|
team: schemaTeamReadPublic.parse(team),
|
||||||
owner: schemaMembershipPublic.parse(team.members[0]),
|
owner: schemaMembershipPublic.parse(team.members[0]),
|
||||||
message: `Team created successfully. We also made user with ID=${ownerId} the owner of this team.`,
|
message: `Team created successfully. We also made user with ID=${effectiveUserId} the owner of this team.`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { schemaQueryIdAsString } from "~/lib/validations/shared/queryIdString";
|
|||||||
* tags:
|
* tags:
|
||||||
* - webhooks
|
* - webhooks
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/webhooks
|
* url: https://docs.cal.com/docs/core-features/webhooks
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, hook removed successfully
|
* description: OK, hook removed successfully
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { schemaWebhookReadPublic } from "~/lib/validations/webhook";
|
|||||||
* tags:
|
* tags:
|
||||||
* - webhooks
|
* - webhooks
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/webhooks
|
* url: https://docs.cal.com/docs/core-features/webhooks
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* description: OK
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ import { schemaWebhookEditBodyParams, schemaWebhookReadPublic } from "~/lib/vali
|
|||||||
* tags:
|
* tags:
|
||||||
* - webhooks
|
* - webhooks
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/webhooks
|
* url: https://docs.cal.com/docs/core-features/webhooks
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, webhook edited successfully
|
* description: OK, webhook edited successfully
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import { schemaWebhookReadPublic } from "~/lib/validations/webhook";
|
|||||||
* tags:
|
* tags:
|
||||||
* - webhooks
|
* - webhooks
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/webhooks
|
* url: https://docs.cal.com/docs/core-features/webhooks
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* description: OK
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ import { schemaWebhookCreateBodyParams, schemaWebhookReadPublic } from "~/lib/va
|
|||||||
* tags:
|
* tags:
|
||||||
* - webhooks
|
* - webhooks
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
* url: https://docs.cal.com/core-features/webhooks
|
* url: https://docs.cal.com/docs/core-features/webhooks
|
||||||
* responses:
|
* responses:
|
||||||
* 201:
|
* 201:
|
||||||
* description: OK, webhook created
|
* description: OK, webhook created
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import prismaMock from "../../../../../../tests/libs/__mocks__/prismaMock";
|
||||||
|
|
||||||
|
import type { Request, Response } from "express";
|
||||||
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import { createMocks } from "node-mocks-http";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import handler from "../../../pages/api/attendees/_post";
|
||||||
|
|
||||||
|
type CustomNextApiRequest = NextApiRequest & Request;
|
||||||
|
type CustomNextApiResponse = NextApiResponse & Response;
|
||||||
|
|
||||||
|
describe("POST /api/attendees", () => {
|
||||||
|
describe("Errors", () => {
|
||||||
|
test("Returns 403 if user is not admin and has no booking", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
bookingId: 1,
|
||||||
|
email: "test@example.com",
|
||||||
|
name: "Test User",
|
||||||
|
timeZone: "UTC",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
prismaMock.booking.findFirst.mockResolvedValue(null);
|
||||||
|
|
||||||
|
req.userId = 123;
|
||||||
|
// req.isAdmin = false;
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(403);
|
||||||
|
expect(JSON.parse(res._getData()).message).toBe("Forbidden");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Returns 200 if user is admin", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
bookingId: 1,
|
||||||
|
email: "test@example.com",
|
||||||
|
name: "Test User",
|
||||||
|
timeZone: "UTC",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const attendeeData = {
|
||||||
|
id: 1,
|
||||||
|
email: "test@example.com",
|
||||||
|
name: "Test User",
|
||||||
|
timeZone: "UTC",
|
||||||
|
bookingId: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
prismaMock.attendee.create.mockResolvedValue(attendeeData);
|
||||||
|
req.isSystemWideAdmin = true;
|
||||||
|
req.userId = 123;
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(JSON.parse(res._getData()).attendee).toEqual(attendeeData);
|
||||||
|
expect(JSON.parse(res._getData()).message).toBe("Attendee created successfully");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Returns 200 if user is not admin but has a booking", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
bookingId: 1,
|
||||||
|
email: "test@example.com",
|
||||||
|
name: "Test User",
|
||||||
|
timeZone: "UTC",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const userBooking = { id: 1 };
|
||||||
|
|
||||||
|
prismaMock.booking.findFirst.mockResolvedValue(userBooking);
|
||||||
|
|
||||||
|
const attendeeData = {
|
||||||
|
id: 1,
|
||||||
|
email: "test@example.com",
|
||||||
|
name: "Test User",
|
||||||
|
timeZone: "UTC",
|
||||||
|
bookingId: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
prismaMock.attendee.create.mockResolvedValue(attendeeData);
|
||||||
|
|
||||||
|
req.userId = 123;
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(JSON.parse(res._getData()).attendee).toEqual(attendeeData);
|
||||||
|
expect(JSON.parse(res._getData()).message).toBe("Attendee created successfully");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Returns 400 if request body is invalid", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
// Missing required fields
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = 123;
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -105,4 +105,87 @@ describe("GET /api/bookings", async () => {
|
|||||||
expect(responseData.bookings.find((b) => b.id === proUserBooking.id)).toBeUndefined();
|
expect(responseData.bookings.find((b) => b.id === proUserBooking.id)).toBeUndefined();
|
||||||
expect(groupedUsers.size).toBeGreaterThanOrEqual(2);
|
expect(groupedUsers.size).toBeGreaterThanOrEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Upcoming bookings feature", () => {
|
||||||
|
it("Returns only upcoming bookings when status=upcoming for regular user", async () => {
|
||||||
|
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "GET",
|
||||||
|
query: {
|
||||||
|
status: "upcoming",
|
||||||
|
},
|
||||||
|
pagination: DefaultPagination,
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = proUser.id;
|
||||||
|
|
||||||
|
const responseData = await handler(req);
|
||||||
|
responseData.bookings.forEach((booking) => {
|
||||||
|
expect(new Date(booking.startTime).getTime()).toBeGreaterThanOrEqual(new Date().getTime());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Returns all bookings when status not specified for regular user", async () => {
|
||||||
|
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "GET",
|
||||||
|
pagination: DefaultPagination,
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = proUser.id;
|
||||||
|
|
||||||
|
const responseData = await handler(req);
|
||||||
|
expect(responseData.bookings.find((b) => b.id === proUserBooking.id)).toBeDefined();
|
||||||
|
|
||||||
|
const { req: req2 } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "GET",
|
||||||
|
pagination: DefaultPagination,
|
||||||
|
});
|
||||||
|
|
||||||
|
req2.userId = proUser.id;
|
||||||
|
|
||||||
|
const responseData2 = await handler(req2);
|
||||||
|
expect(responseData2.bookings.find((b) => b.id === proUserBooking.id)).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Returns only upcoming bookings when status=upcoming for system-wide admin", async () => {
|
||||||
|
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-acme@example.com" } });
|
||||||
|
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "GET",
|
||||||
|
query: {
|
||||||
|
status: "upcoming",
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
take: 100,
|
||||||
|
skip: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
req.isSystemWideAdmin = true;
|
||||||
|
req.userId = adminUser.id;
|
||||||
|
|
||||||
|
const responseData = await handler(req);
|
||||||
|
responseData.bookings.forEach((booking) => {
|
||||||
|
console.log(booking);
|
||||||
|
expect(new Date(booking.startTime).getTime()).toBeGreaterThanOrEqual(new Date().getTime());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Returns only upcoming bookings when status=upcoming for org admin", async () => {
|
||||||
|
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-acme@example.com" } });
|
||||||
|
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "GET",
|
||||||
|
query: {
|
||||||
|
status: "upcoming",
|
||||||
|
},
|
||||||
|
pagination: DefaultPagination,
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = adminUser.id;
|
||||||
|
req.isOrganizationOwnerOrAdmin = true;
|
||||||
|
|
||||||
|
const responseData = await handler(req);
|
||||||
|
responseData.bookings.forEach((booking) => {
|
||||||
|
expect(new Date(booking.startTime).getTime()).toBeGreaterThanOrEqual(new Date().getTime());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -11,6 +11,7 @@ import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
|||||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||||
import { buildBooking, buildEventType, buildWebhook } from "@calcom/lib/test/builder";
|
import { buildBooking, buildEventType, buildWebhook } from "@calcom/lib/test/builder";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
import type { Booking } from "@calcom/prisma";
|
||||||
|
|
||||||
import handler from "../../../pages/api/bookings/_post";
|
import handler from "../../../pages/api/bookings/_post";
|
||||||
|
|
||||||
@@ -157,6 +158,7 @@ describe.skipIf(true)("POST /api/bookings", () => {
|
|||||||
|
|
||||||
describe("Success", () => {
|
describe("Success", () => {
|
||||||
describe("Regular event-type", () => {
|
describe("Regular event-type", () => {
|
||||||
|
let createdBooking: Booking;
|
||||||
test("Creates one single booking", async () => {
|
test("Creates one single booking", async () => {
|
||||||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -181,9 +183,43 @@ describe.skipIf(true)("POST /api/bookings", () => {
|
|||||||
|
|
||||||
await handler(req, res);
|
await handler(req, res);
|
||||||
console.log({ statusCode: res._getStatusCode(), data: JSON.parse(res._getData()) });
|
console.log({ statusCode: res._getStatusCode(), data: JSON.parse(res._getData()) });
|
||||||
|
createdBooking = JSON.parse(res._getData());
|
||||||
expect(prismaMock.booking.create).toHaveBeenCalledTimes(1);
|
expect(prismaMock.booking.create).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Reschedule created booking", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
name: "testReschedule",
|
||||||
|
start: dayjs().add(2, "day").format(),
|
||||||
|
end: dayjs().add(3, "day").format(),
|
||||||
|
eventTypeId: 2,
|
||||||
|
email: "test@example.com",
|
||||||
|
location: "Cal.com Video",
|
||||||
|
timeZone: "America/Montevideo",
|
||||||
|
language: "en",
|
||||||
|
customInputs: [],
|
||||||
|
metadata: {},
|
||||||
|
userId: 4,
|
||||||
|
rescheduleUid: createdBooking.uid,
|
||||||
|
},
|
||||||
|
prisma,
|
||||||
|
});
|
||||||
|
|
||||||
|
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue(buildEventType());
|
||||||
|
prismaMock.booking.findMany.mockResolvedValue([]);
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
console.log({ statusCode: res._getStatusCode(), data: JSON.parse(res._getData()) });
|
||||||
|
const rescheduledBooking = JSON.parse(res._getData()) as Booking;
|
||||||
|
expect(prismaMock.booking.create).toHaveBeenCalledTimes(1);
|
||||||
|
expect(rescheduledBooking.fromReschedule).toEqual(createdBooking.uid);
|
||||||
|
const previousBooking = await prisma.booking.findUnique({
|
||||||
|
where: { uid: createdBooking.uid },
|
||||||
|
});
|
||||||
|
expect(previousBooking?.status).toBe("cancelled");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Recurring event-type", () => {
|
describe("Recurring event-type", () => {
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
import prismaMock from "../../../../../../tests/libs/__mocks__/prismaMock";
|
||||||
|
|
||||||
|
import type { Request, Response } from "express";
|
||||||
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import { createMocks } from "node-mocks-http";
|
||||||
|
import { describe, expect, test, vi, afterEach } from "vitest";
|
||||||
|
|
||||||
|
import { buildEventType } from "@calcom/lib/test/builder";
|
||||||
|
|
||||||
|
import handler from "../../../pages/api/event-types/_post";
|
||||||
|
import checkParentEventOwnership from "../../../pages/api/event-types/_utils/checkParentEventOwnership";
|
||||||
|
import checkTeamEventEditPermission from "../../../pages/api/event-types/_utils/checkTeamEventEditPermission";
|
||||||
|
import checkUserMembership from "../../../pages/api/event-types/_utils/checkUserMembership";
|
||||||
|
import ensureOnlyMembersAsHosts from "../../../pages/api/event-types/_utils/ensureOnlyMembersAsHosts";
|
||||||
|
import { canUserAccessTeamWithRole } from "../../../pages/api/teams/[teamId]/_auth-middleware";
|
||||||
|
|
||||||
|
type CustomNextApiRequest = NextApiRequest & Request;
|
||||||
|
type CustomNextApiResponse = NextApiResponse & Response;
|
||||||
|
|
||||||
|
const adminUserId = 1;
|
||||||
|
const memberUserId = 10;
|
||||||
|
|
||||||
|
vi.mock("../../../pages/api/teams/[teamId]/_auth-middleware", () => ({
|
||||||
|
canUserAccessTeamWithRole: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../../../pages/api/event-types/_utils/checkUserMembership", () => ({
|
||||||
|
default: vi.fn(),
|
||||||
|
}));
|
||||||
|
vi.mock("../../../pages/api/event-types/_utils/checkParentEventOwnership", () => ({
|
||||||
|
default: vi.fn(),
|
||||||
|
}));
|
||||||
|
vi.mock("../../../pages/api/event-types/_utils/checkTeamEventEditPermission", () => ({
|
||||||
|
default: vi.fn(),
|
||||||
|
}));
|
||||||
|
vi.mock("../../../pages/api/event-types/_utils/ensureOnlyMembersAsHosts", () => ({
|
||||||
|
default: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("POST /api/event-types", () => {
|
||||||
|
describe("Errors", () => {
|
||||||
|
test("should throw 401 if a non-admin user tries to create an event type with userId", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
title: "Tennis class",
|
||||||
|
slug: "tennis-class-{{$guid}}",
|
||||||
|
length: 60,
|
||||||
|
hidden: true,
|
||||||
|
userId: memberUserId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(401);
|
||||||
|
expect(JSON.parse(res._getData()).message).toBe("ADMIN required for `userId`");
|
||||||
|
});
|
||||||
|
test("should throw 401 if not system-wide admin and user cannot access teamId with required roles", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
title: "Tennis class",
|
||||||
|
slug: "tennis-class-{{$guid}}",
|
||||||
|
length: 60,
|
||||||
|
hidden: true,
|
||||||
|
teamId: 9999,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
req.userId = memberUserId;
|
||||||
|
vi.mocked(canUserAccessTeamWithRole).mockImplementationOnce(async () => false);
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(401);
|
||||||
|
expect(JSON.parse(res._getData()).message).toBe("ADMIN required for `teamId`");
|
||||||
|
});
|
||||||
|
test("should throw 400 if system-wide admin but neither userId nor teamId provided", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
title: "Tennis class",
|
||||||
|
slug: "tennis-class-{{$guid}}",
|
||||||
|
length: 60,
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
req.isSystemWideAdmin = true;
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(400);
|
||||||
|
expect(JSON.parse(res._getData()).message).toBe("`userId` or `teamId` required");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Success", () => {
|
||||||
|
test("should call checkParentEventOwnership and checkUserMembership if parentId is present", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
title: "Tennis class",
|
||||||
|
slug: "tennis-class-{{$guid}}",
|
||||||
|
length: 60,
|
||||||
|
hidden: true,
|
||||||
|
userId: memberUserId,
|
||||||
|
parentId: 9999,
|
||||||
|
teamId: 9999,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
req.isSystemWideAdmin = true;
|
||||||
|
req.userId = adminUserId;
|
||||||
|
|
||||||
|
vi.mocked(canUserAccessTeamWithRole).mockImplementationOnce(async () => false);
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
expect(checkParentEventOwnership).toHaveBeenCalled();
|
||||||
|
expect(checkUserMembership).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should create event type successfully if all conditions are met", async () => {
|
||||||
|
const eventTypeTest = buildEventType();
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
title: "test title",
|
||||||
|
slug: "test-slug",
|
||||||
|
length: 60,
|
||||||
|
hidden: true,
|
||||||
|
userId: memberUserId,
|
||||||
|
parentId: 9999,
|
||||||
|
teamId: 9999,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
req.isSystemWideAdmin = true;
|
||||||
|
req.userId = adminUserId;
|
||||||
|
|
||||||
|
vi.mocked(canUserAccessTeamWithRole).mockImplementationOnce(async () => true);
|
||||||
|
vi.mocked(checkParentEventOwnership).mockImplementationOnce(async () => undefined);
|
||||||
|
vi.mocked(checkUserMembership).mockImplementationOnce(async () => undefined);
|
||||||
|
vi.mocked(checkTeamEventEditPermission).mockImplementationOnce(async () => undefined);
|
||||||
|
vi.mocked(ensureOnlyMembersAsHosts).mockImplementationOnce(async () => undefined);
|
||||||
|
|
||||||
|
prismaMock.eventType.create.mockResolvedValue(eventTypeTest);
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
const data = JSON.parse(res._getData());
|
||||||
|
|
||||||
|
expect(prismaMock.eventType.create).toHaveBeenCalledTimes(1);
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(data.message).toBe("Event type created successfully");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -3,9 +3,9 @@ import prismaMock from "../../../../../../tests/libs/__mocks__/prismaMock";
|
|||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { createMocks } from "node-mocks-http";
|
import { createMocks } from "node-mocks-http";
|
||||||
import { describe, vi, it, expect, afterEach } from "vitest";
|
import { describe, vi, it, expect, afterEach, beforeEach } from "vitest";
|
||||||
|
|
||||||
import checkLicense from "@calcom/features/ee/common/server/checkLicense";
|
import LicenseKeyService from "@calcom/ee/common/server/LicenseKeyService";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|
||||||
import { isAdminGuard } from "~/lib/utils/isAdmin";
|
import { isAdminGuard } from "~/lib/utils/isAdmin";
|
||||||
@@ -20,20 +20,21 @@ afterEach(() => {
|
|||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.mock("@calcom/features/ee/common/server/checkLicense", () => {
|
vi.mock("@calcom/prisma");
|
||||||
return {
|
vi.mock("~/lib/utils/isAdmin", () => ({
|
||||||
default: vi.fn(),
|
isAdminGuard: vi.fn(),
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock("~/lib/utils/isAdmin", () => {
|
|
||||||
return {
|
|
||||||
isAdminGuard: vi.fn(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Verify API key", () => {
|
describe("Verify API key", () => {
|
||||||
it("It should throw an error if the api key is not valid", async () => {
|
let service: LicenseKeyService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
service = await LicenseKeyService.create();
|
||||||
|
|
||||||
|
vi.spyOn(service, "checkLicense");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should throw an error if the api key is not valid", async () => {
|
||||||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {},
|
body: {},
|
||||||
@@ -43,7 +44,7 @@ describe("Verify API key", () => {
|
|||||||
fn: verifyApiKey,
|
fn: verifyApiKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(checkLicense).mockResolvedValue(false);
|
vi.mocked(service.checkLicense).mockResolvedValue(false);
|
||||||
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: false, scope: null });
|
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: false, scope: null });
|
||||||
|
|
||||||
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
||||||
@@ -53,9 +54,11 @@ describe("Verify API key", () => {
|
|||||||
await middleware.fn(req, res, serverNext);
|
await middleware.fn(req, res, serverNext);
|
||||||
|
|
||||||
expect(middlewareSpy).toBeCalled();
|
expect(middlewareSpy).toBeCalled();
|
||||||
|
|
||||||
expect(res.statusCode).toBe(401);
|
expect(res.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
it("It should throw an error if no api key is provided", async () => {
|
|
||||||
|
it("should throw an error if no api key is provided", async () => {
|
||||||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {},
|
body: {},
|
||||||
@@ -65,7 +68,7 @@ describe("Verify API key", () => {
|
|||||||
fn: verifyApiKey,
|
fn: verifyApiKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(checkLicense).mockResolvedValue(true);
|
vi.mocked(service.checkLicense).mockResolvedValue(true);
|
||||||
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: false, scope: null });
|
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: false, scope: null });
|
||||||
|
|
||||||
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
||||||
@@ -75,10 +78,11 @@ describe("Verify API key", () => {
|
|||||||
await middleware.fn(req, res, serverNext);
|
await middleware.fn(req, res, serverNext);
|
||||||
|
|
||||||
expect(middlewareSpy).toBeCalled();
|
expect(middlewareSpy).toBeCalled();
|
||||||
|
|
||||||
expect(res.statusCode).toBe(401);
|
expect(res.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("It should set correct permissions for system-wide admin", async () => {
|
it("should set correct permissions for system-wide admin", async () => {
|
||||||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {},
|
body: {},
|
||||||
@@ -97,7 +101,7 @@ describe("Verify API key", () => {
|
|||||||
fn: verifyApiKey,
|
fn: verifyApiKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(checkLicense).mockResolvedValue(true);
|
vi.mocked(service.checkLicense).mockResolvedValue(true);
|
||||||
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: true, scope: ScopeOfAdmin.SystemWide });
|
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: true, scope: ScopeOfAdmin.SystemWide });
|
||||||
|
|
||||||
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
||||||
@@ -107,11 +111,12 @@ describe("Verify API key", () => {
|
|||||||
await middleware.fn(req, res, serverNext);
|
await middleware.fn(req, res, serverNext);
|
||||||
|
|
||||||
expect(middlewareSpy).toBeCalled();
|
expect(middlewareSpy).toBeCalled();
|
||||||
|
|
||||||
expect(req.isSystemWideAdmin).toBe(true);
|
expect(req.isSystemWideAdmin).toBe(true);
|
||||||
expect(req.isOrganizationOwnerOrAdmin).toBe(false);
|
expect(req.isOrganizationOwnerOrAdmin).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("It should set correct permissions for org-level admin", async () => {
|
it("should set correct permissions for org-level admin", async () => {
|
||||||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {},
|
body: {},
|
||||||
@@ -130,7 +135,7 @@ describe("Verify API key", () => {
|
|||||||
fn: verifyApiKey,
|
fn: verifyApiKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(checkLicense).mockResolvedValue(true);
|
vi.mocked(service.checkLicense).mockResolvedValue(true);
|
||||||
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: true, scope: ScopeOfAdmin.OrgOwnerOrAdmin });
|
vi.mocked(isAdminGuard).mockResolvedValue({ isAdmin: true, scope: ScopeOfAdmin.OrgOwnerOrAdmin });
|
||||||
|
|
||||||
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
const serverNext = vi.fn((next: void) => Promise.resolve(next));
|
||||||
@@ -140,6 +145,7 @@ describe("Verify API key", () => {
|
|||||||
await middleware.fn(req, res, serverNext);
|
await middleware.fn(req, res, serverNext);
|
||||||
|
|
||||||
expect(middlewareSpy).toBeCalled();
|
expect(middlewareSpy).toBeCalled();
|
||||||
|
|
||||||
expect(req.isSystemWideAdmin).toBe(false);
|
expect(req.isSystemWideAdmin).toBe(false);
|
||||||
expect(req.isOrganizationOwnerOrAdmin).toBe(true);
|
expect(req.isOrganizationOwnerOrAdmin).toBe(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
import prismaMock from "../../../../../../tests/libs/__mocks__/prismaMock";
|
||||||
|
|
||||||
|
import type { Request, Response } from "express";
|
||||||
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import { createMocks } from "node-mocks-http";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import { HttpError } from "@calcom/lib/http-error";
|
||||||
|
|
||||||
|
import handler from "../../../pages/api/selected-calendars/_post";
|
||||||
|
|
||||||
|
type CustomNextApiRequest = NextApiRequest & Request;
|
||||||
|
type CustomNextApiResponse = NextApiResponse & Response;
|
||||||
|
|
||||||
|
describe("POST /api/selected-calendars", () => {
|
||||||
|
describe("Errors", () => {
|
||||||
|
test("Returns 403 if non-admin user tries to set userId in body", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
integration: "google",
|
||||||
|
externalId: "ext123",
|
||||||
|
userId: 444444,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = 333333;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await handler(req, res);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e).toBeInstanceOf(HttpError);
|
||||||
|
expect((e as HttpError).statusCode).toBe(403);
|
||||||
|
expect((e as HttpError).message).toBe("ADMIN required for userId");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Returns 400 if request body is invalid", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
integration: "google",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = 333333;
|
||||||
|
req.isSystemWideAdmin = true;
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(400);
|
||||||
|
expect(JSON.parse(res._getData()).message).toBe("invalid_type in 'externalId': Required");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Success", () => {
|
||||||
|
test("Creates selected calendar if user is admin and sets bodyUserId", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
query: {
|
||||||
|
apiKey: "validApiKey",
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
integration: "google",
|
||||||
|
externalId: "ext123",
|
||||||
|
userId: 444444,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = 333333;
|
||||||
|
req.isSystemWideAdmin = true;
|
||||||
|
|
||||||
|
prismaMock.user.findFirstOrThrow.mockResolvedValue({
|
||||||
|
id: 444444,
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
prismaMock.selectedCalendar.create.mockResolvedValue({
|
||||||
|
credentialId: 1,
|
||||||
|
integration: "google",
|
||||||
|
externalId: "ext123",
|
||||||
|
userId: 444444,
|
||||||
|
});
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
const responseData = JSON.parse(res._getData());
|
||||||
|
expect(responseData.selected_calendar.credentialId).toBe(1);
|
||||||
|
expect(responseData.message).toBe("Selected Calendar created successfully");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Creates selected calendar if user is non-admin and does not set bodyUserId", async () => {
|
||||||
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
query: {
|
||||||
|
apiKey: "validApiKey",
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
integration: "google",
|
||||||
|
externalId: "ext123",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
req.userId = 333333;
|
||||||
|
|
||||||
|
prismaMock.selectedCalendar.create.mockResolvedValue({
|
||||||
|
credentialId: 1,
|
||||||
|
integration: "google",
|
||||||
|
externalId: "ext123",
|
||||||
|
userId: 333333,
|
||||||
|
});
|
||||||
|
|
||||||
|
await handler(req, res);
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
const responseData = JSON.parse(res._getData());
|
||||||
|
expect(responseData.selected_calendar.credentialId).toBe(1);
|
||||||
|
expect(responseData.message).toBe("Selected Calendar created successfully");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -58,7 +58,7 @@ describe("isAdmin guard", () => {
|
|||||||
expect(scope).toBe(ScopeOfAdmin.SystemWide);
|
expect(scope).toBe(ScopeOfAdmin.SystemWide);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Returns org-wide admin when user is set as such", async () => {
|
it("Returns org-wide admin when user is set as such & admin API access is granted", async () => {
|
||||||
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: {},
|
body: {},
|
||||||
@@ -67,10 +67,21 @@ describe("isAdmin guard", () => {
|
|||||||
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-acme@example.com" } });
|
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-acme@example.com" } });
|
||||||
|
|
||||||
req.userId = adminUser.id;
|
req.userId = adminUser.id;
|
||||||
|
|
||||||
const { isAdmin, scope } = await isAdminGuard(req);
|
const { isAdmin, scope } = await isAdminGuard(req);
|
||||||
|
|
||||||
expect(isAdmin).toBe(true);
|
expect(isAdmin).toBe(true);
|
||||||
expect(scope).toBe(ScopeOfAdmin.OrgOwnerOrAdmin);
|
expect(scope).toBe(ScopeOfAdmin.OrgOwnerOrAdmin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Returns no admin when user is set as org admin but admin API access is revoked", async () => {
|
||||||
|
const { req } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
|
method: "POST",
|
||||||
|
body: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const adminUser = await prisma.user.findFirstOrThrow({ where: { email: "owner1-dunder@example.com" } });
|
||||||
|
|
||||||
|
req.userId = adminUser.id;
|
||||||
|
const { isAdmin } = await isAdminGuard(req);
|
||||||
|
expect(isAdmin).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -14,8 +14,11 @@ NEXT_PUBLIC_SENTRY_DSN=
|
|||||||
|
|
||||||
# Stripe Billing
|
# Stripe Billing
|
||||||
STRIPE_PRICE_ID_STARTER=
|
STRIPE_PRICE_ID_STARTER=
|
||||||
|
STRIPE_PRICE_ID_STARTER_OVERAGE=
|
||||||
STRIPE_PRICE_ID_ESSENTIALS=
|
STRIPE_PRICE_ID_ESSENTIALS=
|
||||||
|
STRIPE_PRICE_ID_ESSENTIALS_OVERAGE=
|
||||||
STRIPE_PRICE_ID_ENTERPRISE=
|
STRIPE_PRICE_ID_ENTERPRISE=
|
||||||
|
STRIPE_PRICE_ID_ENTERPRISE_OVERAGE=
|
||||||
STRIPE_API_KEY=
|
STRIPE_API_KEY=
|
||||||
STRIPE_WEBHOOK_SECRET=
|
STRIPE_WEBHOOK_SECRET=
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
<a href="http://nestjs.com/" target="blank"><img src="https://github.com/user-attachments/assets/ce7c2ecf-6097-469a-8512-c846a9fb665d" height="200" alt="Nest Logo" /></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
Cal.com is using the [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -10,5 +10,6 @@
|
|||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.(t|j)s$": "ts-jest"
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
},
|
},
|
||||||
"setupFiles": ["<rootDir>/test/setEnvVars.ts"]
|
"setupFiles": ["<rootDir>/test/setEnvVars.ts"],
|
||||||
|
"reporters": ["default", "jest-summarizing-reporter"]
|
||||||
}
|
}
|
||||||
@@ -18,20 +18,21 @@
|
|||||||
"test:watch": "yarn dev:build && jest --watch",
|
"test:watch": "yarn dev:build && jest --watch",
|
||||||
"test:cov": "yarn dev:build && jest --coverage",
|
"test:cov": "yarn dev:build && jest --coverage",
|
||||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||||
"test:e2e": "yarn dev:build && jest --runInBand --config ./jest-e2e.json",
|
"test:e2e": "yarn dev:build && jest --runInBand --detectOpenHandles --forceExit --config ./jest-e2e.json",
|
||||||
"prisma": "yarn workspace @calcom/prisma prisma",
|
"prisma": "yarn workspace @calcom/prisma prisma",
|
||||||
"generate-schemas": "yarn prisma generate && yarn prisma format",
|
"generate-schemas": "yarn prisma generate && yarn prisma format",
|
||||||
"copy-swagger-module": "ts-node -r tsconfig-paths/register swagger/copy-swagger-module.ts"
|
"copy-swagger-module": "ts-node -r tsconfig-paths/register swagger/copy-swagger-module.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@calcom/platform-constants": "*",
|
"@calcom/platform-constants": "*",
|
||||||
"@calcom/platform-libraries-0.0.18": "npm:@calcom/platform-libraries@0.0.18",
|
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.28",
|
||||||
"@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2",
|
"@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2",
|
||||||
"@calcom/platform-types": "*",
|
"@calcom/platform-types": "*",
|
||||||
"@calcom/platform-utils": "*",
|
"@calcom/platform-utils": "*",
|
||||||
"@calcom/prisma": "*",
|
"@calcom/prisma": "*",
|
||||||
"@golevelup/ts-jest": "^0.4.0",
|
"@golevelup/ts-jest": "^0.4.0",
|
||||||
"@microsoft/microsoft-graph-types-beta": "^0.42.0-preview",
|
"@microsoft/microsoft-graph-types-beta": "^0.42.0-preview",
|
||||||
|
"@nestjs/bull": "^10.1.1",
|
||||||
"@nestjs/common": "^10.0.0",
|
"@nestjs/common": "^10.0.0",
|
||||||
"@nestjs/config": "^3.1.1",
|
"@nestjs/config": "^3.1.1",
|
||||||
"@nestjs/core": "^10.0.0",
|
"@nestjs/core": "^10.0.0",
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
"@nestjs/throttler": "^5.1.2",
|
"@nestjs/throttler": "^5.1.2",
|
||||||
"@sentry/node": "^8.8.0",
|
"@sentry/node": "^8.8.0",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
|
"bull": "^4.12.4",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.0",
|
"class-validator": "^0.14.0",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ import { JwtModule } from "@/modules/jwt/jwt.module";
|
|||||||
import { PrismaModule } from "@/modules/prisma/prisma.module";
|
import { PrismaModule } from "@/modules/prisma/prisma.module";
|
||||||
import { RedisModule } from "@/modules/redis/redis.module";
|
import { RedisModule } from "@/modules/redis/redis.module";
|
||||||
import { RedisService } from "@/modules/redis/redis.service";
|
import { RedisService } from "@/modules/redis/redis.service";
|
||||||
|
import { BullModule } from "@nestjs/bull";
|
||||||
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from "@nestjs/common";
|
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from "@nestjs/common";
|
||||||
import { ConfigModule } from "@nestjs/config";
|
import { ConfigModule } from "@nestjs/config";
|
||||||
import { APP_INTERCEPTOR, RouterModule } from "@nestjs/core";
|
import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";
|
||||||
import { seconds, ThrottlerModule } from "@nestjs/throttler";
|
import { seconds, ThrottlerGuard, ThrottlerModule } from "@nestjs/throttler";
|
||||||
import { ThrottlerStorageRedisService } from "nestjs-throttler-storage-redis";
|
import { ThrottlerStorageRedisService } from "nestjs-throttler-storage-redis";
|
||||||
|
|
||||||
import { AppController } from "./app.controller";
|
import { AppController } from "./app.controller";
|
||||||
@@ -26,21 +27,20 @@ import { AppController } from "./app.controller";
|
|||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
load: [appConfig],
|
load: [appConfig],
|
||||||
}),
|
}),
|
||||||
|
|
||||||
RedisModule,
|
RedisModule,
|
||||||
|
BullModule.forRoot({
|
||||||
|
redis: `${process.env.REDIS_URL}${process.env.NODE_ENV === "production" ? "?tls=true" : ""}`,
|
||||||
|
}),
|
||||||
ThrottlerModule.forRootAsync({
|
ThrottlerModule.forRootAsync({
|
||||||
imports: [RedisModule],
|
imports: [RedisModule],
|
||||||
inject: [RedisService],
|
inject: [RedisService],
|
||||||
useFactory: (redisService: RedisService) => ({
|
useFactory: (redisService: RedisService) => ({
|
||||||
throttlers: [
|
throttlers: [
|
||||||
{
|
{
|
||||||
name: "short",
|
name: "long",
|
||||||
ttl: seconds(10),
|
ttl: seconds(60), // Time to live for the long period in seconds
|
||||||
limit: 3,
|
limit: 120, // Maximum number of requests within the long ttl
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "medium",
|
|
||||||
ttl: seconds(30),
|
|
||||||
limit: 10,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storage: new ThrottlerStorageRedisService(redisService.redis),
|
storage: new ThrottlerStorageRedisService(redisService.redis),
|
||||||
@@ -57,6 +57,10 @@ import { AppController } from "./app.controller";
|
|||||||
provide: APP_INTERCEPTOR,
|
provide: APP_INTERCEPTOR,
|
||||||
useClass: ResponseInterceptor,
|
useClass: ResponseInterceptor,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: APP_GUARD,
|
||||||
|
useClass: ThrottlerGuard,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule implements NestModule {
|
export class AppModule implements NestModule {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { bootstrap } from "@/app";
|
import { bootstrap } from "@/app";
|
||||||
import { AppModule } from "@/app.module";
|
import { AppModule } from "@/app.module";
|
||||||
|
import { CreateBookingInput } from "@/ee/bookings/inputs/create-booking.input";
|
||||||
import { GetBookingOutput } from "@/ee/bookings/outputs/get-booking.output";
|
import { GetBookingOutput } from "@/ee/bookings/outputs/get-booking.output";
|
||||||
import { GetBookingsOutput } from "@/ee/bookings/outputs/get-bookings.output";
|
import { GetBookingsOutput } from "@/ee/bookings/outputs/get-bookings.output";
|
||||||
import { CreateScheduleInput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/inputs/create-schedule.input";
|
import { CreateScheduleInput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/inputs/create-schedule.input";
|
||||||
@@ -19,7 +20,7 @@ import { UserRepositoryFixture } from "test/fixtures/repository/users.repository
|
|||||||
import { withApiAuth } from "test/utils/withApiAuth";
|
import { withApiAuth } from "test/utils/withApiAuth";
|
||||||
|
|
||||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||||
import { handleNewBooking } from "@calcom/platform-libraries-0.0.18";
|
import { handleNewBooking } from "@calcom/platform-libraries";
|
||||||
import { ApiSuccessResponse, ApiResponse } from "@calcom/platform-types";
|
import { ApiSuccessResponse, ApiResponse } from "@calcom/platform-types";
|
||||||
|
|
||||||
describe("Bookings Endpoints", () => {
|
describe("Bookings Endpoints", () => {
|
||||||
@@ -90,7 +91,10 @@ describe("Bookings Endpoints", () => {
|
|||||||
const bookingTimeZone = "Europe/London";
|
const bookingTimeZone = "Europe/London";
|
||||||
const bookingLanguage = "en";
|
const bookingLanguage = "en";
|
||||||
const bookingHashedLink = "";
|
const bookingHashedLink = "";
|
||||||
const bookingMetadata = {};
|
const bookingMetadata = {
|
||||||
|
timeFormat: "12",
|
||||||
|
meetingType: "organizer-phone",
|
||||||
|
};
|
||||||
const bookingResponses = {
|
const bookingResponses = {
|
||||||
name: "tester",
|
name: "tester",
|
||||||
email: "tester@example.com",
|
email: "tester@example.com",
|
||||||
@@ -102,7 +106,7 @@ describe("Bookings Endpoints", () => {
|
|||||||
guests: [],
|
guests: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const body = {
|
const body: CreateBookingInput = {
|
||||||
start: bookingStart,
|
start: bookingStart,
|
||||||
end: bookingEnd,
|
end: bookingEnd,
|
||||||
eventTypeId: bookingEventTypeId,
|
eventTypeId: bookingEventTypeId,
|
||||||
@@ -135,6 +139,64 @@ describe("Bookings Endpoints", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("should reschedule a booking", () => {
|
||||||
|
it("should reschedule with updated start time, end time & metadata", async () => {
|
||||||
|
const newBookingStart = "2040-05-21T12:30:00.000Z";
|
||||||
|
const newBookingEnd = "2040-05-21T13:30:00.000Z";
|
||||||
|
const bookingEventTypeId = eventTypeId;
|
||||||
|
const bookingTimeZone = "Europe/London";
|
||||||
|
const bookingLanguage = "en";
|
||||||
|
const bookingHashedLink = "";
|
||||||
|
const newBookingMetadata = {
|
||||||
|
timeFormat: "24",
|
||||||
|
meetingType: "attendee-phone",
|
||||||
|
};
|
||||||
|
const bookingResponses = {
|
||||||
|
name: "tester",
|
||||||
|
email: "tester@example.com",
|
||||||
|
location: {
|
||||||
|
value: "link",
|
||||||
|
optionValue: "",
|
||||||
|
},
|
||||||
|
notes: "test",
|
||||||
|
guests: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const body: CreateBookingInput = {
|
||||||
|
rescheduleUid: createdBooking.uid,
|
||||||
|
start: newBookingStart,
|
||||||
|
end: newBookingEnd,
|
||||||
|
eventTypeId: bookingEventTypeId,
|
||||||
|
timeZone: bookingTimeZone,
|
||||||
|
language: bookingLanguage,
|
||||||
|
metadata: newBookingMetadata,
|
||||||
|
hashedLink: bookingHashedLink,
|
||||||
|
responses: bookingResponses,
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.post("/v2/bookings")
|
||||||
|
.send(body)
|
||||||
|
.expect(201)
|
||||||
|
.then(async (response) => {
|
||||||
|
const responseBody: ApiSuccessResponse<Awaited<ReturnType<typeof handleNewBooking>>> =
|
||||||
|
response.body;
|
||||||
|
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
||||||
|
expect(responseBody.data).toBeDefined();
|
||||||
|
expect(responseBody.data.userPrimaryEmail).toBeDefined();
|
||||||
|
expect(responseBody.data.userPrimaryEmail).toEqual(userEmail);
|
||||||
|
expect(responseBody.data.id).toBeDefined();
|
||||||
|
expect(responseBody.data.uid).toBeDefined();
|
||||||
|
expect(responseBody.data.startTime).toEqual(newBookingStart);
|
||||||
|
expect(responseBody.data.eventTypeId).toEqual(bookingEventTypeId);
|
||||||
|
expect(responseBody.data.user.timeZone).toEqual(bookingTimeZone);
|
||||||
|
expect(responseBody.data.metadata).toEqual(newBookingMetadata);
|
||||||
|
|
||||||
|
createdBooking = responseBody.data;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should get bookings", async () => {
|
it("should get bookings", async () => {
|
||||||
return request(app.getHttpServer())
|
return request(app.getHttpServer())
|
||||||
.get("/v2/bookings?filters[status]=upcoming")
|
.get("/v2/bookings?filters[status]=upcoming")
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import {
|
|||||||
getBookingInfo,
|
getBookingInfo,
|
||||||
handleCancelBooking,
|
handleCancelBooking,
|
||||||
getBookingForReschedule,
|
getBookingForReschedule,
|
||||||
} from "@calcom/platform-libraries-0.0.18";
|
} from "@calcom/platform-libraries";
|
||||||
import { GetBookingsInput, CancelBookingInput, Status } from "@calcom/platform-types";
|
import { GetBookingsInput, CancelBookingInput, Status } from "@calcom/platform-types";
|
||||||
import { ApiResponse } from "@calcom/platform-types";
|
import { ApiResponse } from "@calcom/platform-types";
|
||||||
import { PrismaClient } from "@calcom/prisma";
|
import { PrismaClient } from "@calcom/prisma";
|
||||||
@@ -150,17 +150,21 @@ export class BookingsController {
|
|||||||
@Req() req: BookingRequest,
|
@Req() req: BookingRequest,
|
||||||
@Body() body: CreateBookingInput,
|
@Body() body: CreateBookingInput,
|
||||||
@Headers(X_CAL_CLIENT_ID) clientId?: string
|
@Headers(X_CAL_CLIENT_ID) clientId?: string
|
||||||
): Promise<ApiResponse<unknown>> {
|
): Promise<ApiResponse<Partial<BookingResponse>>> {
|
||||||
const oAuthClientId = clientId?.toString();
|
const oAuthClientId = clientId?.toString();
|
||||||
|
|
||||||
const { orgSlug, locationUrl } = body;
|
const { orgSlug, locationUrl } = body;
|
||||||
req.headers["x-cal-force-slug"] = orgSlug;
|
req.headers["x-cal-force-slug"] = orgSlug;
|
||||||
try {
|
try {
|
||||||
const booking = await handleNewBooking(
|
const booking = await handleNewBooking(
|
||||||
await this.createNextApiBookingRequest(req, oAuthClientId, locationUrl)
|
await this.createNextApiBookingRequest(req, oAuthClientId, locationUrl)
|
||||||
);
|
);
|
||||||
|
if (booking.userId && booking.uid && booking.startTime) {
|
||||||
void (await this.billingService.increaseUsageByClientId(oAuthClientId!));
|
void (await this.billingService.increaseUsageByUserId(booking.userId, {
|
||||||
|
uid: booking.uid,
|
||||||
|
startTime: booking.startTime,
|
||||||
|
fromReschedule: booking.fromReschedule,
|
||||||
|
}));
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
status: SUCCESS_STATUS,
|
status: SUCCESS_STATUS,
|
||||||
data: booking,
|
data: booking,
|
||||||
@@ -177,14 +181,22 @@ export class BookingsController {
|
|||||||
@Param("bookingId") bookingId: string,
|
@Param("bookingId") bookingId: string,
|
||||||
@Body() _: CancelBookingInput,
|
@Body() _: CancelBookingInput,
|
||||||
@Headers(X_CAL_CLIENT_ID) clientId?: string
|
@Headers(X_CAL_CLIENT_ID) clientId?: string
|
||||||
): Promise<ApiResponse> {
|
): Promise<ApiResponse<{ bookingId: number; bookingUid: string; onlyRemovedAttendee: boolean }>> {
|
||||||
const oAuthClientId = clientId?.toString();
|
const oAuthClientId = clientId?.toString();
|
||||||
if (bookingId) {
|
if (bookingId) {
|
||||||
try {
|
try {
|
||||||
req.body.id = parseInt(bookingId);
|
req.body.id = parseInt(bookingId);
|
||||||
await handleCancelBooking(await this.createNextApiBookingRequest(req, oAuthClientId));
|
const res = await handleCancelBooking(await this.createNextApiBookingRequest(req, oAuthClientId));
|
||||||
|
if (!res.onlyRemovedAttendee) {
|
||||||
|
void (await this.billingService.cancelUsageByBookingUid(res.bookingUid));
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
status: SUCCESS_STATUS,
|
status: SUCCESS_STATUS,
|
||||||
|
data: {
|
||||||
|
bookingId: res.bookingId,
|
||||||
|
bookingUid: res.bookingUid,
|
||||||
|
onlyRemovedAttendee: res.onlyRemovedAttendee,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.handleBookingErrors(err);
|
this.handleBookingErrors(err);
|
||||||
@@ -199,6 +211,7 @@ export class BookingsController {
|
|||||||
@Permissions([BOOKING_WRITE])
|
@Permissions([BOOKING_WRITE])
|
||||||
@UseGuards(ApiAuthGuard)
|
@UseGuards(ApiAuthGuard)
|
||||||
async markNoShow(
|
async markNoShow(
|
||||||
|
@GetUser("id") userId: number,
|
||||||
@Body() body: MarkNoShowInput,
|
@Body() body: MarkNoShowInput,
|
||||||
@Param("bookingUid") bookingUid: string
|
@Param("bookingUid") bookingUid: string
|
||||||
): Promise<MarkNoShowOutput> {
|
): Promise<MarkNoShowOutput> {
|
||||||
@@ -207,6 +220,7 @@ export class BookingsController {
|
|||||||
bookingUid: bookingUid,
|
bookingUid: bookingUid,
|
||||||
attendees: body.attendees,
|
attendees: body.attendees,
|
||||||
noShowHost: body.noShowHost,
|
noShowHost: body.noShowHost,
|
||||||
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { status: SUCCESS_STATUS, data: markNoShowResponse };
|
return { status: SUCCESS_STATUS, data: markNoShowResponse };
|
||||||
@@ -228,7 +242,14 @@ export class BookingsController {
|
|||||||
await this.createNextApiBookingRequest(req, oAuthClientId)
|
await this.createNextApiBookingRequest(req, oAuthClientId)
|
||||||
);
|
);
|
||||||
|
|
||||||
void (await this.billingService.increaseUsageByClientId(oAuthClientId!));
|
createdBookings.forEach(async (booking) => {
|
||||||
|
if (booking.userId && booking.uid && booking.startTime) {
|
||||||
|
void (await this.billingService.increaseUsageByUserId(booking.userId, {
|
||||||
|
uid: booking.uid,
|
||||||
|
startTime: booking.startTime,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: SUCCESS_STATUS,
|
status: SUCCESS_STATUS,
|
||||||
@@ -253,7 +274,15 @@ export class BookingsController {
|
|||||||
await this.createNextApiBookingRequest(req, oAuthClientId)
|
await this.createNextApiBookingRequest(req, oAuthClientId)
|
||||||
);
|
);
|
||||||
|
|
||||||
void (await this.billingService.increaseUsageByClientId(oAuthClientId!));
|
if (instantMeeting.userId && instantMeeting.bookingUid) {
|
||||||
|
const now = new Date();
|
||||||
|
// add a 10 secondes delay to the usage incrementation to give some time to cancel the booking if needed
|
||||||
|
now.setSeconds(now.getSeconds() + 10);
|
||||||
|
void (await this.billingService.increaseUsageByUserId(instantMeeting.userId, {
|
||||||
|
uid: instantMeeting.bookingUid,
|
||||||
|
startTime: now,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: SUCCESS_STATUS,
|
status: SUCCESS_STATUS,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { CreateBookingInput } from "@/ee/bookings/inputs/create-booking.input";
|
import { CreateBookingInput } from "@/ee/bookings/inputs/create-booking.input";
|
||||||
import { IsBoolean, IsNumber, IsOptional } from "class-validator";
|
import { IsBoolean, IsNumber, IsOptional } from "class-validator";
|
||||||
|
|
||||||
import type { AppsStatus } from "@calcom/platform-libraries-0.0.18";
|
import type { AppsStatus } from "@calcom/platform-libraries";
|
||||||
|
|
||||||
export class CreateRecurringBookingInput extends CreateBookingInput {
|
export class CreateRecurringBookingInput extends CreateBookingInput {
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ class HandleMarkNoShowData {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
noShowHost?: boolean;
|
noShowHost?: boolean;
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
messageKey?: string;
|
|
||||||
|
|
||||||
@ValidateNested()
|
@ValidateNested()
|
||||||
@Type(() => Attendee)
|
@Type(() => Attendee)
|
||||||
@IsArray()
|
@IsArray()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { CalendarsRepository } from "@/ee/calendars/calendars.repository";
|
||||||
import { CalendarsController } from "@/ee/calendars/controllers/calendars.controller";
|
import { CalendarsController } from "@/ee/calendars/controllers/calendars.controller";
|
||||||
import { AppleCalendarService } from "@/ee/calendars/services/apple-calendar.service";
|
import { AppleCalendarService } from "@/ee/calendars/services/apple-calendar.service";
|
||||||
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
||||||
@@ -21,6 +22,7 @@ import { Module } from "@nestjs/common";
|
|||||||
AppleCalendarService,
|
AppleCalendarService,
|
||||||
SelectedCalendarsRepository,
|
SelectedCalendarsRepository,
|
||||||
AppsRepository,
|
AppsRepository,
|
||||||
|
CalendarsRepository,
|
||||||
],
|
],
|
||||||
controllers: [CalendarsController],
|
controllers: [CalendarsController],
|
||||||
exports: [CalendarsService],
|
exports: [CalendarsService],
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
|
||||||
|
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
|
||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
|
const credentialForCalendarRepositorySelect = Prisma.validator<Prisma.CredentialSelect>()({
|
||||||
|
id: true,
|
||||||
|
appId: true,
|
||||||
|
type: true,
|
||||||
|
userId: true,
|
||||||
|
user: {
|
||||||
|
select: {
|
||||||
|
email: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
teamId: true,
|
||||||
|
key: true,
|
||||||
|
invalid: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CalendarsRepository {
|
||||||
|
constructor(private readonly dbRead: PrismaReadService, private readonly dbWrite: PrismaWriteService) {}
|
||||||
|
|
||||||
|
async getCalendarCredentials(credentialId: number, userId: number) {
|
||||||
|
return await this.dbRead.prisma.credential.findFirst({
|
||||||
|
where: {
|
||||||
|
id: credentialId,
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
...credentialForCalendarRepositorySelect,
|
||||||
|
app: {
|
||||||
|
select: {
|
||||||
|
slug: true,
|
||||||
|
categories: true,
|
||||||
|
dirName: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteCredentials(credentialId: number) {
|
||||||
|
return await this.dbWrite.prisma.credential.delete({
|
||||||
|
where: {
|
||||||
|
id: credentialId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-9
@@ -1,5 +1,6 @@
|
|||||||
import { bootstrap } from "@/app";
|
import { bootstrap } from "@/app";
|
||||||
import { AppModule } from "@/app.module";
|
import { AppModule } from "@/app.module";
|
||||||
|
import { DeletedCalendarCredentialsOutputResponseDto } from "@/ee/calendars/outputs/delete-calendar-credentials.output";
|
||||||
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
||||||
import { HttpExceptionFilter } from "@/filters/http-exception.filter";
|
import { HttpExceptionFilter } from "@/filters/http-exception.filter";
|
||||||
import { PrismaExceptionFilter } from "@/filters/prisma-exception.filter";
|
import { PrismaExceptionFilter } from "@/filters/prisma-exception.filter";
|
||||||
@@ -18,6 +19,7 @@ import { TokensRepositoryFixture } from "test/fixtures/repository/tokens.reposit
|
|||||||
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
|
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
|
||||||
import { CalendarsServiceMock } from "test/mocks/calendars-service-mock";
|
import { CalendarsServiceMock } from "test/mocks/calendars-service-mock";
|
||||||
|
|
||||||
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||||
import {
|
import {
|
||||||
GOOGLE_CALENDAR,
|
GOOGLE_CALENDAR,
|
||||||
OFFICE_365_CALENDAR,
|
OFFICE_365_CALENDAR,
|
||||||
@@ -105,15 +107,16 @@ describe("Platform Calendars Endpoints", () => {
|
|||||||
.expect(401);
|
.expect(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`/GET/v2/calendars/${OFFICE_365_CALENDAR}/connect: it should redirect to auth-url for office 365 calendar oauth with valid access token `, async () => {
|
// TODO: Uncomment this once CI is ready to run proper Office365 tests
|
||||||
const response = await request(app.getHttpServer())
|
// it(`/GET/v2/calendars/${OFFICE_365_CALENDAR}/connect: it should redirect to auth-url for office 365 calendar oauth with valid access token `, async () => {
|
||||||
.get(`/v2/calendars/${OFFICE_365_CALENDAR}/connect`)
|
// const response = await request(app.getHttpServer())
|
||||||
.set("Authorization", `Bearer ${accessTokenSecret}`)
|
// .get(`/v2/calendars/${OFFICE_365_CALENDAR}/connect`)
|
||||||
.set("Origin", CLIENT_REDIRECT_URI)
|
// .set("Authorization", `Bearer ${accessTokenSecret}`)
|
||||||
.expect(200);
|
// .set("Origin", CLIENT_REDIRECT_URI)
|
||||||
const data = response.body.data;
|
// .expect(200);
|
||||||
expect(data.authUrl).toBeDefined();
|
// const data = response.body.data;
|
||||||
});
|
// expect(data.authUrl).toBeDefined();
|
||||||
|
// });
|
||||||
|
|
||||||
it(`/GET/v2/calendars/${GOOGLE_CALENDAR}/connect: it should redirect to auth-url for google calendar oauth with valid access token `, async () => {
|
it(`/GET/v2/calendars/${GOOGLE_CALENDAR}/connect: it should redirect to auth-url for google calendar oauth with valid access token `, async () => {
|
||||||
const response = await request(app.getHttpServer())
|
const response = await request(app.getHttpServer())
|
||||||
@@ -189,6 +192,26 @@ describe("Platform Calendars Endpoints", () => {
|
|||||||
.expect(200);
|
.expect(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.skip(`/POST/v2/calendars/${OFFICE_365_CALENDAR}/disconnect: it should respond with a 201 returning back the user deleted calendar credentials`, async () => {
|
||||||
|
const body = {
|
||||||
|
id: 10,
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.post(`/v2/calendars/${OFFICE_365_CALENDAR}/disconnect`)
|
||||||
|
.set("Authorization", `Bearer ${accessTokenSecret}`)
|
||||||
|
.send(body)
|
||||||
|
.expect(201)
|
||||||
|
.then(async (response) => {
|
||||||
|
const responseBody: Promise<DeletedCalendarCredentialsOutputResponseDto> = response.body;
|
||||||
|
|
||||||
|
expect((await responseBody).status).toEqual(SUCCESS_STATUS);
|
||||||
|
expect((await responseBody).data).toBeDefined();
|
||||||
|
expect((await responseBody).data.id).toEqual(body.id);
|
||||||
|
expect((await responseBody).data.userId).toEqual(user.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await oauthClientRepositoryFixture.delete(oAuthClient.id);
|
await oauthClientRepositoryFixture.delete(oAuthClient.id);
|
||||||
await teamRepositoryFixture.delete(organization.id);
|
await teamRepositoryFixture.delete(organization.id);
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
|
import { CalendarsRepository } from "@/ee/calendars/calendars.repository";
|
||||||
|
import { DeleteCalendarCredentialsInputBodyDto } from "@/ee/calendars/input/delete-calendar-credentials.input";
|
||||||
import { GetBusyTimesOutput } from "@/ee/calendars/outputs/busy-times.output";
|
import { GetBusyTimesOutput } from "@/ee/calendars/outputs/busy-times.output";
|
||||||
import { ConnectedCalendarsOutput } from "@/ee/calendars/outputs/connected-calendars.output";
|
import { ConnectedCalendarsOutput } from "@/ee/calendars/outputs/connected-calendars.output";
|
||||||
|
import {
|
||||||
|
DeletedCalendarCredentialsOutputResponseDto,
|
||||||
|
DeletedCalendarCredentialsOutputDto,
|
||||||
|
} from "@/ee/calendars/outputs/delete-calendar-credentials.output";
|
||||||
import { AppleCalendarService } from "@/ee/calendars/services/apple-calendar.service";
|
import { AppleCalendarService } from "@/ee/calendars/services/apple-calendar.service";
|
||||||
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
||||||
import { GoogleCalendarService } from "@/ee/calendars/services/gcal.service";
|
import { GoogleCalendarService } from "@/ee/calendars/services/gcal.service";
|
||||||
@@ -27,6 +33,7 @@ import {
|
|||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { ApiTags as DocsTags } from "@nestjs/swagger";
|
import { ApiTags as DocsTags } from "@nestjs/swagger";
|
||||||
import { User } from "@prisma/client";
|
import { User } from "@prisma/client";
|
||||||
|
import { plainToClass } from "class-transformer";
|
||||||
import { Request } from "express";
|
import { Request } from "express";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@@ -50,7 +57,8 @@ export class CalendarsController {
|
|||||||
private readonly calendarsService: CalendarsService,
|
private readonly calendarsService: CalendarsService,
|
||||||
private readonly outlookService: OutlookService,
|
private readonly outlookService: OutlookService,
|
||||||
private readonly googleCalendarService: GoogleCalendarService,
|
private readonly googleCalendarService: GoogleCalendarService,
|
||||||
private readonly appleCalendarService: AppleCalendarService
|
private readonly appleCalendarService: AppleCalendarService,
|
||||||
|
private readonly calendarsRepository: CalendarsRepository
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@UseGuards(ApiAuthGuard)
|
@UseGuards(ApiAuthGuard)
|
||||||
@@ -183,4 +191,29 @@ export class CalendarsController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(ApiAuthGuard)
|
||||||
|
@Post("/:calendar/disconnect")
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async deleteCalendarCredentials(
|
||||||
|
@Param("calendar") calendar: string,
|
||||||
|
@Body() body: DeleteCalendarCredentialsInputBodyDto,
|
||||||
|
@GetUser() user: UserWithProfile
|
||||||
|
): Promise<DeletedCalendarCredentialsOutputResponseDto> {
|
||||||
|
const { id: credentialId } = body;
|
||||||
|
await this.calendarsService.checkCalendarCredentials(credentialId, user.id);
|
||||||
|
|
||||||
|
const { id, type, userId, teamId, appId, invalid } = await this.calendarsRepository.deleteCredentials(
|
||||||
|
credentialId
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: SUCCESS_STATUS,
|
||||||
|
data: plainToClass(
|
||||||
|
DeletedCalendarCredentialsOutputDto,
|
||||||
|
{ id, type, userId, teamId, appId, invalid },
|
||||||
|
{ strategy: "excludeAll" }
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
import { Expose } from "class-transformer";
|
||||||
|
import { IsInt } from "class-validator";
|
||||||
|
|
||||||
|
export class DeleteCalendarCredentialsInputBodyDto {
|
||||||
|
@IsInt()
|
||||||
|
@Expose()
|
||||||
|
@ApiProperty({
|
||||||
|
example: 10,
|
||||||
|
description: "Credential ID of the calendar to delete, as returned by the /calendars endpoint",
|
||||||
|
type: "integer",
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
readonly id!: number;
|
||||||
|
}
|
||||||
@@ -105,7 +105,7 @@ class Primary {
|
|||||||
credentialId!: number;
|
credentialId!: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Calendar {
|
export class Calendar {
|
||||||
@IsEmail()
|
@IsEmail()
|
||||||
externalId!: string;
|
externalId!: string;
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ class Calendar {
|
|||||||
credentialId!: number;
|
credentialId!: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConnectedCalendar {
|
export class ConnectedCalendar {
|
||||||
@ValidateNested()
|
@ValidateNested()
|
||||||
@IsObject()
|
@IsObject()
|
||||||
integration!: Integration;
|
integration!: Integration;
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
import { Expose, Type } from "class-transformer";
|
||||||
|
import { IsString, ValidateNested, IsEnum, IsInt, IsBoolean } from "class-validator";
|
||||||
|
|
||||||
|
import { ERROR_STATUS, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||||
|
|
||||||
|
export class DeletedCalendarCredentialsOutputDto {
|
||||||
|
@IsInt()
|
||||||
|
@Expose()
|
||||||
|
readonly id!: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@Expose()
|
||||||
|
readonly type!: string;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@Expose()
|
||||||
|
readonly userId!: number | null;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@Expose()
|
||||||
|
readonly teamId!: number | null;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@Expose()
|
||||||
|
readonly appId!: string | null;
|
||||||
|
|
||||||
|
@IsBoolean()
|
||||||
|
@Expose()
|
||||||
|
readonly invalid!: boolean | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DeletedCalendarCredentialsOutputResponseDto {
|
||||||
|
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
|
||||||
|
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
|
||||||
|
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
|
||||||
|
|
||||||
|
@Expose()
|
||||||
|
@ValidateNested()
|
||||||
|
@Type(() => DeletedCalendarCredentialsOutputDto)
|
||||||
|
data!: DeletedCalendarCredentialsOutputDto;
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import { BadRequestException, UnauthorizedException } from "@nestjs/common";
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
|
|
||||||
import { SUCCESS_STATUS, APPLE_CALENDAR_TYPE, APPLE_CALENDAR_ID } from "@calcom/platform-constants";
|
import { SUCCESS_STATUS, APPLE_CALENDAR_TYPE, APPLE_CALENDAR_ID } from "@calcom/platform-constants";
|
||||||
import { symmetricEncrypt, CalendarService } from "@calcom/platform-libraries-0.0.18";
|
import { symmetricEncrypt, CalendarService } from "@calcom/platform-libraries";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppleCalendarService implements CredentialSyncCalendarApp {
|
export class AppleCalendarService implements CredentialSyncCalendarApp {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { CalendarsRepository } from "@/ee/calendars/calendars.repository";
|
||||||
import { AppsRepository } from "@/modules/apps/apps.repository";
|
import { AppsRepository } from "@/modules/apps/apps.repository";
|
||||||
import {
|
import {
|
||||||
CredentialsRepository,
|
CredentialsRepository,
|
||||||
@@ -17,7 +18,7 @@ import { User } from "@prisma/client";
|
|||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { getConnectedDestinationCalendars, getBusyCalendarTimes } from "@calcom/platform-libraries-0.0.18";
|
import { getConnectedDestinationCalendars, getBusyCalendarTimes } from "@calcom/platform-libraries";
|
||||||
import { Calendar } from "@calcom/platform-types";
|
import { Calendar } from "@calcom/platform-types";
|
||||||
import { PrismaClient } from "@calcom/prisma";
|
import { PrismaClient } from "@calcom/prisma";
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ export class CalendarsService {
|
|||||||
private readonly usersRepository: UsersRepository,
|
private readonly usersRepository: UsersRepository,
|
||||||
private readonly credentialsRepository: CredentialsRepository,
|
private readonly credentialsRepository: CredentialsRepository,
|
||||||
private readonly appsRepository: AppsRepository,
|
private readonly appsRepository: AppsRepository,
|
||||||
|
private readonly calendarsRepository: CalendarsRepository,
|
||||||
private readonly dbRead: PrismaReadService,
|
private readonly dbRead: PrismaReadService,
|
||||||
private readonly dbWrite: PrismaWriteService,
|
private readonly dbWrite: PrismaWriteService,
|
||||||
private readonly config: ConfigService
|
private readonly config: ConfigService
|
||||||
@@ -136,4 +138,11 @@ export class CalendarsService {
|
|||||||
|
|
||||||
return { client_id, client_secret };
|
return { client_id, client_secret };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkCalendarCredentials(credentialId: number, userId: number) {
|
||||||
|
const credential = await this.calendarsRepository.getCalendarCredentials(credentialId, userId);
|
||||||
|
if (!credential) {
|
||||||
|
throw new NotFoundException("Calendar credentials not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -35,7 +35,7 @@ import {
|
|||||||
EventTypesPublic,
|
EventTypesPublic,
|
||||||
eventTypeBookingFields,
|
eventTypeBookingFields,
|
||||||
eventTypeLocations,
|
eventTypeLocations,
|
||||||
} from "@calcom/platform-libraries-0.0.18";
|
} from "@calcom/platform-libraries";
|
||||||
import { ApiSuccessResponse } from "@calcom/platform-types";
|
import { ApiSuccessResponse } from "@calcom/platform-types";
|
||||||
|
|
||||||
describe("Event types Endpoints", () => {
|
describe("Event types Endpoints", () => {
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ import {
|
|||||||
import { ApiTags as DocsTags } from "@nestjs/swagger";
|
import { ApiTags as DocsTags } from "@nestjs/swagger";
|
||||||
|
|
||||||
import { EVENT_TYPE_READ, EVENT_TYPE_WRITE, SUCCESS_STATUS } from "@calcom/platform-constants";
|
import { EVENT_TYPE_READ, EVENT_TYPE_WRITE, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||||
import { getPublicEvent, getEventTypesByViewer } from "@calcom/platform-libraries-0.0.18";
|
import { getPublicEvent, getEventTypesByViewer } from "@calcom/platform-libraries-0.0.2";
|
||||||
import { PrismaClient } from "@calcom/prisma";
|
import { PrismaClient } from "@calcom/prisma";
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
|
|||||||
import { UserWithProfile } from "@/modules/users/users.repository";
|
import { UserWithProfile } from "@/modules/users/users.repository";
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
|
|
||||||
import { getEventTypeById } from "@calcom/platform-libraries-0.0.18";
|
import { getEventTypeById } from "@calcom/platform-libraries";
|
||||||
import type { PrismaClient } from "@calcom/prisma";
|
import type { PrismaClient } from "@calcom/prisma";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
+4
@@ -177,6 +177,10 @@ export class BookingField_2024_04_15 {
|
|||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => Source)
|
@Type(() => Source)
|
||||||
sources?: Source[];
|
sources?: Source[];
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
disableOnPrefill?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RecurringEvent_2024_04_15 {
|
export class RecurringEvent_2024_04_15 {
|
||||||
|
|||||||
+4
@@ -87,6 +87,10 @@ class BookingField {
|
|||||||
@Type(() => Source)
|
@Type(() => Source)
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
sources?: Source[];
|
sources?: Source[];
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
disableOnPrefill?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Organization {
|
class Organization {
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ import {
|
|||||||
updateEventType,
|
updateEventType,
|
||||||
EventTypesPublic,
|
EventTypesPublic,
|
||||||
getEventTypesPublic,
|
getEventTypesPublic,
|
||||||
} from "@calcom/platform-libraries-0.0.18";
|
} from "@calcom/platform-libraries";
|
||||||
import { EventType } from "@calcom/prisma/client";
|
import { EventType } from "@calcom/prisma/client";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
+605
-130
@@ -1,5 +1,6 @@
|
|||||||
import { bootstrap } from "@/app";
|
import { bootstrap } from "@/app";
|
||||||
import { AppModule } from "@/app.module";
|
import { AppModule } from "@/app.module";
|
||||||
|
import { CreateEventTypeInput_2024_04_15 } from "@/ee/event-types/event-types_2024_04_15/inputs/create-event-type.input";
|
||||||
import { EventTypesModule_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/event-types.module";
|
import { EventTypesModule_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/event-types.module";
|
||||||
import { HttpExceptionFilter } from "@/filters/http-exception.filter";
|
import { HttpExceptionFilter } from "@/filters/http-exception.filter";
|
||||||
import { PrismaExceptionFilter } from "@/filters/prisma-exception.filter";
|
import { PrismaExceptionFilter } from "@/filters/prisma-exception.filter";
|
||||||
@@ -9,10 +10,11 @@ import { UsersModule } from "@/modules/users/users.module";
|
|||||||
import { INestApplication } from "@nestjs/common";
|
import { INestApplication } from "@nestjs/common";
|
||||||
import { NestExpressApplication } from "@nestjs/platform-express";
|
import { NestExpressApplication } from "@nestjs/platform-express";
|
||||||
import { Test } from "@nestjs/testing";
|
import { Test } from "@nestjs/testing";
|
||||||
import { PlatformOAuthClient, Team, User } from "@prisma/client";
|
import { PlatformOAuthClient, Team, User, Schedule } from "@prisma/client";
|
||||||
import * as request from "supertest";
|
import * as request from "supertest";
|
||||||
import { EventTypesRepositoryFixture } from "test/fixtures/repository/event-types.repository.fixture";
|
import { EventTypesRepositoryFixture } from "test/fixtures/repository/event-types.repository.fixture";
|
||||||
import { OAuthClientRepositoryFixture } from "test/fixtures/repository/oauth-client.repository.fixture";
|
import { OAuthClientRepositoryFixture } from "test/fixtures/repository/oauth-client.repository.fixture";
|
||||||
|
import { SchedulesRepositoryFixture } from "test/fixtures/repository/schedules.repository.fixture";
|
||||||
import { TeamRepositoryFixture } from "test/fixtures/repository/team.repository.fixture";
|
import { TeamRepositoryFixture } from "test/fixtures/repository/team.repository.fixture";
|
||||||
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
|
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
|
||||||
import { withApiAuth } from "test/utils/withApiAuth";
|
import { withApiAuth } from "test/utils/withApiAuth";
|
||||||
@@ -24,6 +26,8 @@ import {
|
|||||||
EventTypeOutput_2024_06_14,
|
EventTypeOutput_2024_06_14,
|
||||||
UpdateEventTypeInput_2024_06_14,
|
UpdateEventTypeInput_2024_06_14,
|
||||||
} from "@calcom/platform-types";
|
} from "@calcom/platform-types";
|
||||||
|
import { BookingWindowPeriodInputTypeEnum_2024_06_14 } from "@calcom/platform-types/dist/event-types/event-types_2024_06_14/inputs/enums/booking-window.enum";
|
||||||
|
import { SchedulingType } from "@calcom/prisma/enums";
|
||||||
|
|
||||||
describe("Event types Endpoints", () => {
|
describe("Event types Endpoints", () => {
|
||||||
describe("Not authenticated", () => {
|
describe("Not authenticated", () => {
|
||||||
@@ -63,12 +67,398 @@ describe("Event types Endpoints", () => {
|
|||||||
let oauthClientRepositoryFixture: OAuthClientRepositoryFixture;
|
let oauthClientRepositoryFixture: OAuthClientRepositoryFixture;
|
||||||
let teamRepositoryFixture: TeamRepositoryFixture;
|
let teamRepositoryFixture: TeamRepositoryFixture;
|
||||||
let eventTypesRepositoryFixture: EventTypesRepositoryFixture;
|
let eventTypesRepositoryFixture: EventTypesRepositoryFixture;
|
||||||
|
let schedulesRepostoryFixture: SchedulesRepositoryFixture;
|
||||||
|
|
||||||
const userEmail = "event-types-test-e2e@api.com";
|
const userEmail = "event-types-test-e2e@api.com";
|
||||||
|
const falseTestEmail = "false-event-types@api.com";
|
||||||
const name = "bob-the-builder";
|
const name = "bob-the-builder";
|
||||||
const username = name;
|
const username = name;
|
||||||
let eventType: EventTypeOutput_2024_06_14;
|
let eventType: EventTypeOutput_2024_06_14;
|
||||||
let user: User;
|
let user: User;
|
||||||
|
let falseTestUser: User;
|
||||||
|
let firstSchedule: Schedule;
|
||||||
|
let secondSchedule: Schedule;
|
||||||
|
let falseTestSchedule: Schedule;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const moduleRef = await withApiAuth(
|
||||||
|
userEmail,
|
||||||
|
Test.createTestingModule({
|
||||||
|
providers: [PrismaExceptionFilter, HttpExceptionFilter],
|
||||||
|
imports: [AppModule, UsersModule, EventTypesModule_2024_06_14, TokensModule],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.overrideGuard(PermissionsGuard)
|
||||||
|
.useValue({
|
||||||
|
canActivate: () => true,
|
||||||
|
})
|
||||||
|
.compile();
|
||||||
|
|
||||||
|
app = moduleRef.createNestApplication();
|
||||||
|
bootstrap(app as NestExpressApplication);
|
||||||
|
|
||||||
|
oauthClientRepositoryFixture = new OAuthClientRepositoryFixture(moduleRef);
|
||||||
|
userRepositoryFixture = new UserRepositoryFixture(moduleRef);
|
||||||
|
teamRepositoryFixture = new TeamRepositoryFixture(moduleRef);
|
||||||
|
eventTypesRepositoryFixture = new EventTypesRepositoryFixture(moduleRef);
|
||||||
|
schedulesRepostoryFixture = new SchedulesRepositoryFixture(moduleRef);
|
||||||
|
|
||||||
|
organization = await teamRepositoryFixture.create({ name: "organization" });
|
||||||
|
oAuthClient = await createOAuthClient(organization.id);
|
||||||
|
user = await userRepositoryFixture.create({
|
||||||
|
email: userEmail,
|
||||||
|
name,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
|
||||||
|
falseTestUser = await userRepositoryFixture.create({
|
||||||
|
email: falseTestEmail,
|
||||||
|
name: "false-test",
|
||||||
|
username: falseTestEmail,
|
||||||
|
});
|
||||||
|
|
||||||
|
firstSchedule = await schedulesRepostoryFixture.create({
|
||||||
|
userId: user.id,
|
||||||
|
name: "work",
|
||||||
|
timeZone: "Europe/Rome",
|
||||||
|
});
|
||||||
|
|
||||||
|
secondSchedule = await schedulesRepostoryFixture.create({
|
||||||
|
userId: user.id,
|
||||||
|
name: "chill",
|
||||||
|
timeZone: "Europe/Rome",
|
||||||
|
});
|
||||||
|
|
||||||
|
falseTestSchedule = await schedulesRepostoryFixture.create({
|
||||||
|
userId: falseTestUser.id,
|
||||||
|
name: "work",
|
||||||
|
timeZone: "Europe/Rome",
|
||||||
|
});
|
||||||
|
|
||||||
|
await app.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createOAuthClient(organizationId: number) {
|
||||||
|
const data = {
|
||||||
|
logo: "logo-url",
|
||||||
|
name: "name",
|
||||||
|
redirectUris: ["redirect-uri"],
|
||||||
|
permissions: 32,
|
||||||
|
};
|
||||||
|
const secret = "secret";
|
||||||
|
|
||||||
|
const client = await oauthClientRepositoryFixture.create(organizationId, data, secret);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should be defined", () => {
|
||||||
|
expect(oauthClientRepositoryFixture).toBeDefined();
|
||||||
|
expect(userRepositoryFixture).toBeDefined();
|
||||||
|
expect(oAuthClient).toBeDefined();
|
||||||
|
expect(user).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not allow creating an event type with schedule user does not own", async () => {
|
||||||
|
const scheduleId = falseTestSchedule.id;
|
||||||
|
|
||||||
|
const body: CreateEventTypeInput_2024_06_14 = {
|
||||||
|
title: "Coding class",
|
||||||
|
slug: "coding-class",
|
||||||
|
description: "Let's learn how to code like a pro.",
|
||||||
|
lengthInMinutes: 60,
|
||||||
|
locations: [
|
||||||
|
{
|
||||||
|
type: "integration",
|
||||||
|
integration: "cal-video",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
bookingFields: [
|
||||||
|
{
|
||||||
|
type: "select",
|
||||||
|
label: "select which language you want to learn",
|
||||||
|
slug: "select-language",
|
||||||
|
required: true,
|
||||||
|
placeholder: "select language",
|
||||||
|
options: ["javascript", "python", "cobol"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
scheduleId,
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.post("/api/v2/event-types")
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
.send(body)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create an event type", async () => {
|
||||||
|
const body: CreateEventTypeInput_2024_06_14 = {
|
||||||
|
title: "Coding class",
|
||||||
|
slug: "coding-class",
|
||||||
|
description: "Let's learn how to code like a pro.",
|
||||||
|
lengthInMinutes: 60,
|
||||||
|
locations: [
|
||||||
|
{
|
||||||
|
type: "integration",
|
||||||
|
integration: "cal-video",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
bookingFields: [
|
||||||
|
{
|
||||||
|
type: "select",
|
||||||
|
label: "select which language you want to learn",
|
||||||
|
slug: "select-language",
|
||||||
|
required: true,
|
||||||
|
placeholder: "select language",
|
||||||
|
options: ["javascript", "python", "cobol"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
scheduleId: firstSchedule.id,
|
||||||
|
bookingLimitsCount: {
|
||||||
|
day: 2,
|
||||||
|
week: 5,
|
||||||
|
},
|
||||||
|
onlyShowFirstAvailableSlot: true,
|
||||||
|
bookingLimitsDuration: {
|
||||||
|
day: 60,
|
||||||
|
week: 100,
|
||||||
|
},
|
||||||
|
offsetStart: 30,
|
||||||
|
bookingWindow: {
|
||||||
|
type: BookingWindowPeriodInputTypeEnum_2024_06_14.calendarDays,
|
||||||
|
value: 30,
|
||||||
|
rolling: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.post("/api/v2/event-types")
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
.send(body)
|
||||||
|
.expect(201)
|
||||||
|
.then(async (response) => {
|
||||||
|
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
||||||
|
const createdEventType = responseBody.data;
|
||||||
|
expect(createdEventType).toHaveProperty("id");
|
||||||
|
expect(createdEventType.title).toEqual(body.title);
|
||||||
|
expect(createdEventType.description).toEqual(body.description);
|
||||||
|
expect(createdEventType.lengthInMinutes).toEqual(body.lengthInMinutes);
|
||||||
|
expect(createdEventType.locations).toEqual(body.locations);
|
||||||
|
expect(createdEventType.bookingFields).toEqual(body.bookingFields);
|
||||||
|
expect(createdEventType.ownerId).toEqual(user.id);
|
||||||
|
expect(createdEventType.scheduleId).toEqual(firstSchedule.id);
|
||||||
|
expect(createdEventType.bookingLimitsCount).toEqual(body.bookingLimitsCount);
|
||||||
|
expect(createdEventType.onlyShowFirstAvailableSlot).toEqual(body.onlyShowFirstAvailableSlot);
|
||||||
|
expect(createdEventType.bookingLimitsDuration).toEqual(body.bookingLimitsDuration);
|
||||||
|
expect(createdEventType.offsetStart).toEqual(body.offsetStart);
|
||||||
|
expect(createdEventType.bookingWindow).toEqual(body.bookingWindow);
|
||||||
|
eventType = responseBody.data;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update event type", async () => {
|
||||||
|
const newTitle = "Coding class in Italian!";
|
||||||
|
|
||||||
|
const body: UpdateEventTypeInput_2024_06_14 = {
|
||||||
|
title: newTitle,
|
||||||
|
scheduleId: secondSchedule.id,
|
||||||
|
bookingLimitsCount: {
|
||||||
|
day: 4,
|
||||||
|
week: 10,
|
||||||
|
},
|
||||||
|
onlyShowFirstAvailableSlot: true,
|
||||||
|
bookingLimitsDuration: {
|
||||||
|
day: 100,
|
||||||
|
week: 200,
|
||||||
|
},
|
||||||
|
offsetStart: 50,
|
||||||
|
bookingWindow: {
|
||||||
|
type: BookingWindowPeriodInputTypeEnum_2024_06_14.businessDays,
|
||||||
|
value: 40,
|
||||||
|
rolling: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.patch(`/api/v2/event-types/${eventType.id}`)
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
.send(body)
|
||||||
|
.expect(200)
|
||||||
|
.then(async (response) => {
|
||||||
|
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
||||||
|
const updatedEventType = responseBody.data;
|
||||||
|
expect(updatedEventType.title).toEqual(body.title);
|
||||||
|
|
||||||
|
expect(updatedEventType.id).toEqual(eventType.id);
|
||||||
|
expect(updatedEventType.title).toEqual(newTitle);
|
||||||
|
expect(updatedEventType.description).toEqual(eventType.description);
|
||||||
|
expect(updatedEventType.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
||||||
|
expect(updatedEventType.locations).toEqual(eventType.locations);
|
||||||
|
expect(updatedEventType.bookingFields).toEqual(eventType.bookingFields);
|
||||||
|
expect(updatedEventType.ownerId).toEqual(user.id);
|
||||||
|
expect(updatedEventType.scheduleId).toEqual(secondSchedule.id);
|
||||||
|
expect(updatedEventType.bookingLimitsCount).toEqual(body.bookingLimitsCount);
|
||||||
|
expect(updatedEventType.onlyShowFirstAvailableSlot).toEqual(body.onlyShowFirstAvailableSlot);
|
||||||
|
expect(updatedEventType.bookingLimitsDuration).toEqual(body.bookingLimitsDuration);
|
||||||
|
expect(updatedEventType.offsetStart).toEqual(body.offsetStart);
|
||||||
|
expect(updatedEventType.bookingWindow).toEqual(body.bookingWindow);
|
||||||
|
|
||||||
|
eventType.title = newTitle;
|
||||||
|
eventType.scheduleId = secondSchedule.id;
|
||||||
|
eventType.bookingLimitsCount = updatedEventType.bookingLimitsCount;
|
||||||
|
eventType.onlyShowFirstAvailableSlot = updatedEventType.onlyShowFirstAvailableSlot;
|
||||||
|
eventType.bookingLimitsDuration = updatedEventType.bookingLimitsDuration;
|
||||||
|
eventType.offsetStart = updatedEventType.offsetStart;
|
||||||
|
eventType.bookingWindow = updatedEventType.bookingWindow;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not allow to update event type with scheduleId user does not own", async () => {
|
||||||
|
const body: UpdateEventTypeInput_2024_06_14 = {
|
||||||
|
scheduleId: falseTestSchedule.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.patch(`/api/v2/event-types/${eventType.id}`)
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
.send(body)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`/GET/:id`, async () => {
|
||||||
|
const response = await request(app.getHttpServer())
|
||||||
|
.get(`/api/v2/event-types/${eventType.id}`)
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
||||||
|
.set("Authorization", `Bearer whatever`)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
||||||
|
const fetchedEventType = responseBody.data;
|
||||||
|
|
||||||
|
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
||||||
|
expect(responseBody.data).toBeDefined();
|
||||||
|
expect(fetchedEventType.id).toEqual(eventType.id);
|
||||||
|
expect(fetchedEventType.title).toEqual(eventType.title);
|
||||||
|
expect(fetchedEventType.description).toEqual(eventType.description);
|
||||||
|
expect(fetchedEventType.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
||||||
|
expect(fetchedEventType.locations).toEqual(eventType.locations);
|
||||||
|
expect(fetchedEventType.bookingFields).toEqual(eventType.bookingFields);
|
||||||
|
expect(fetchedEventType.ownerId).toEqual(user.id);
|
||||||
|
expect(fetchedEventType.bookingLimitsCount).toEqual(eventType.bookingLimitsCount);
|
||||||
|
expect(fetchedEventType.onlyShowFirstAvailableSlot).toEqual(eventType.onlyShowFirstAvailableSlot);
|
||||||
|
expect(fetchedEventType.bookingLimitsDuration).toEqual(eventType.bookingLimitsDuration);
|
||||||
|
expect(fetchedEventType.offsetStart).toEqual(eventType.offsetStart);
|
||||||
|
expect(fetchedEventType.bookingWindow).toEqual(eventType.bookingWindow);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`/GET/even-types by username`, async () => {
|
||||||
|
const response = await request(app.getHttpServer())
|
||||||
|
.get(`/api/v2/event-types?username=${username}`)
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
||||||
|
.set("Authorization", `Bearer whatever`)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14[]> = response.body;
|
||||||
|
|
||||||
|
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
||||||
|
expect(responseBody.data).toBeDefined();
|
||||||
|
expect(responseBody.data?.length).toEqual(1);
|
||||||
|
|
||||||
|
const fetchedEventType = responseBody.data?.[0];
|
||||||
|
|
||||||
|
expect(fetchedEventType?.id).toEqual(eventType.id);
|
||||||
|
expect(fetchedEventType?.title).toEqual(eventType.title);
|
||||||
|
expect(fetchedEventType?.description).toEqual(eventType.description);
|
||||||
|
expect(fetchedEventType?.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
||||||
|
expect(fetchedEventType?.locations).toEqual(eventType.locations);
|
||||||
|
expect(fetchedEventType?.bookingFields).toEqual(eventType.bookingFields);
|
||||||
|
expect(fetchedEventType?.ownerId).toEqual(user.id);
|
||||||
|
expect(fetchedEventType.bookingLimitsCount).toEqual(eventType.bookingLimitsCount);
|
||||||
|
expect(fetchedEventType.onlyShowFirstAvailableSlot).toEqual(eventType.onlyShowFirstAvailableSlot);
|
||||||
|
expect(fetchedEventType.bookingLimitsDuration).toEqual(eventType.bookingLimitsDuration);
|
||||||
|
expect(fetchedEventType.offsetStart).toEqual(eventType.offsetStart);
|
||||||
|
expect(fetchedEventType.bookingWindow).toEqual(eventType.bookingWindow);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`/GET/event-types by username and eventSlug`, async () => {
|
||||||
|
const response = await request(app.getHttpServer())
|
||||||
|
.get(`/api/v2/event-types?username=${username}&eventSlug=${eventType.slug}`)
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
||||||
|
.set("Authorization", `Bearer whatever`)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14[]> = response.body;
|
||||||
|
const fetchedEventType = responseBody.data[0];
|
||||||
|
|
||||||
|
expect(fetchedEventType?.id).toEqual(eventType.id);
|
||||||
|
expect(fetchedEventType?.title).toEqual(eventType.title);
|
||||||
|
expect(fetchedEventType?.description).toEqual(eventType.description);
|
||||||
|
expect(fetchedEventType?.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
||||||
|
expect(fetchedEventType?.locations).toEqual(eventType.locations);
|
||||||
|
expect(fetchedEventType?.bookingFields).toEqual(eventType.bookingFields);
|
||||||
|
expect(fetchedEventType?.ownerId).toEqual(user.id);
|
||||||
|
expect(fetchedEventType.bookingLimitsCount).toEqual(eventType.bookingLimitsCount);
|
||||||
|
expect(fetchedEventType.onlyShowFirstAvailableSlot).toEqual(eventType.onlyShowFirstAvailableSlot);
|
||||||
|
expect(fetchedEventType.bookingLimitsDuration).toEqual(eventType.bookingLimitsDuration);
|
||||||
|
expect(fetchedEventType.offsetStart).toEqual(eventType.offsetStart);
|
||||||
|
expect(fetchedEventType.bookingWindow).toEqual(eventType.bookingWindow);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`/GET/:id not existing`, async () => {
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.get(`/api/v2/event-types/1000`)
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
|
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
||||||
|
.set("Authorization", `Bearer whatever`)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should delete event type", async () => {
|
||||||
|
return request(app.getHttpServer()).delete(`/api/v2/event-types/${eventType.id}`).expect(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await oauthClientRepositoryFixture.delete(oAuthClient.id);
|
||||||
|
await teamRepositoryFixture.delete(organization.id);
|
||||||
|
try {
|
||||||
|
await eventTypesRepositoryFixture.delete(eventType.id);
|
||||||
|
} catch (e) {
|
||||||
|
// Event type might have been deleted by the test
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await userRepositoryFixture.delete(user.id);
|
||||||
|
} catch (e) {
|
||||||
|
// User might have been deleted by the test
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await userRepositoryFixture.delete(falseTestUser.id);
|
||||||
|
} catch (e) {
|
||||||
|
// User might have been deleted by the test
|
||||||
|
}
|
||||||
|
await app.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Handle legacy event-types booking fields", () => {
|
||||||
|
let app: INestApplication;
|
||||||
|
|
||||||
|
let oAuthClient: PlatformOAuthClient;
|
||||||
|
let organization: Team;
|
||||||
|
let userRepositoryFixture: UserRepositoryFixture;
|
||||||
|
let oauthClientRepositoryFixture: OAuthClientRepositoryFixture;
|
||||||
|
let teamRepositoryFixture: TeamRepositoryFixture;
|
||||||
|
let eventTypesRepositoryFixture: EventTypesRepositoryFixture;
|
||||||
|
|
||||||
|
const userEmail = "legacy-event-types-test-e2e@api.com";
|
||||||
|
const name = "bob-the-builder";
|
||||||
|
const username = name;
|
||||||
|
let user: User;
|
||||||
|
let legacyEventTypeId1: number;
|
||||||
|
let legacyEventTypeId2: number;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const moduleRef = await withApiAuth(
|
const moduleRef = await withApiAuth(
|
||||||
@@ -123,164 +513,249 @@ describe("Event types Endpoints", () => {
|
|||||||
expect(user).toBeDefined();
|
expect(user).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create an event type", async () => {
|
it("should not allow creating an event type with input of event-types version 2024_04_15", async () => {
|
||||||
const body: CreateEventTypeInput_2024_06_14 = {
|
const body: CreateEventTypeInput_2024_04_15 = {
|
||||||
title: "Coding class",
|
title: "Coding class",
|
||||||
slug: "coding-class",
|
slug: "coding-class",
|
||||||
description: "Let's learn how to code like a pro.",
|
description: "Let's learn how to code like a pro.",
|
||||||
lengthInMinutes: 60,
|
length: 60,
|
||||||
locations: [
|
locations: [{ type: "integrations:daily" }],
|
||||||
{
|
|
||||||
type: "integration",
|
|
||||||
integration: "cal-video",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
bookingFields: [
|
|
||||||
{
|
|
||||||
type: "select",
|
|
||||||
label: "select which language you want to learn",
|
|
||||||
slug: "select-language",
|
|
||||||
required: true,
|
|
||||||
placeholder: "select language",
|
|
||||||
options: ["javascript", "python", "cobol"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return request(app.getHttpServer())
|
return request(app.getHttpServer())
|
||||||
.post("/api/v2/event-types")
|
.post("/api/v2/event-types")
|
||||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
.send(body)
|
.send(body)
|
||||||
.expect(201)
|
.expect(400);
|
||||||
.then(async (response) => {
|
|
||||||
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
|
||||||
const createdEventType = responseBody.data;
|
|
||||||
expect(createdEventType).toHaveProperty("id");
|
|
||||||
expect(createdEventType.title).toEqual(body.title);
|
|
||||||
expect(createdEventType.description).toEqual(body.description);
|
|
||||||
expect(createdEventType.lengthInMinutes).toEqual(body.lengthInMinutes);
|
|
||||||
expect(createdEventType.locations).toEqual(body.locations);
|
|
||||||
expect(createdEventType.bookingFields).toEqual(body.bookingFields);
|
|
||||||
expect(createdEventType.ownerId).toEqual(user.id);
|
|
||||||
|
|
||||||
eventType = responseBody.data;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update event type", async () => {
|
it("should return empty bookingFields if system fields are the only one in database", async () => {
|
||||||
const newTitle = "Coding class in Italian!";
|
const legacyEventTypeInput = {
|
||||||
|
title: "legacy event type",
|
||||||
const body: UpdateEventTypeInput_2024_06_14 = {
|
description: "legacy event type description",
|
||||||
title: newTitle,
|
length: 40,
|
||||||
|
hidden: false,
|
||||||
|
slug: "legacy-event-type",
|
||||||
|
locations: [],
|
||||||
|
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||||
|
bookingFields: [
|
||||||
|
{
|
||||||
|
name: "name",
|
||||||
|
type: "name",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system",
|
||||||
|
required: true,
|
||||||
|
defaultLabel: "your_name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "email",
|
||||||
|
type: "email",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system",
|
||||||
|
required: true,
|
||||||
|
defaultLabel: "email_address",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "location",
|
||||||
|
type: "radioInput",
|
||||||
|
label: "",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system",
|
||||||
|
required: false,
|
||||||
|
placeholder: "",
|
||||||
|
defaultLabel: "location",
|
||||||
|
getOptionsAt: "locations",
|
||||||
|
optionsInputs: {
|
||||||
|
phone: { type: "phone", required: true, placeholder: "" },
|
||||||
|
attendeeInPerson: { type: "address", required: true, placeholder: "" },
|
||||||
|
},
|
||||||
|
hideWhenJustOneOption: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "title",
|
||||||
|
type: "text",
|
||||||
|
hidden: true,
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: true,
|
||||||
|
defaultLabel: "what_is_this_meeting_about",
|
||||||
|
defaultPlaceholder: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "notes",
|
||||||
|
type: "textarea",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: false,
|
||||||
|
defaultLabel: "additional_notes",
|
||||||
|
defaultPlaceholder: "share_additional_notes",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "guests",
|
||||||
|
type: "multiemail",
|
||||||
|
hidden: false,
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: false,
|
||||||
|
defaultLabel: "additional_guests",
|
||||||
|
defaultPlaceholder: "email",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rescheduleReason",
|
||||||
|
type: "textarea",
|
||||||
|
views: [{ id: "reschedule", label: "Reschedule View" }],
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: false,
|
||||||
|
defaultLabel: "reason_for_reschedule",
|
||||||
|
defaultPlaceholder: "reschedule_placeholder",
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
const legacyEventType = await eventTypesRepositoryFixture.create(legacyEventTypeInput, user.id);
|
||||||
|
legacyEventTypeId1 = legacyEventType.id;
|
||||||
|
|
||||||
return request(app.getHttpServer())
|
return request(app.getHttpServer())
|
||||||
.patch(`/api/v2/event-types/${eventType.id}`)
|
.get(`/api/v2/event-types/${legacyEventTypeId1}`)
|
||||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
.send(body)
|
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
||||||
const updatedEventType = responseBody.data;
|
const fetchedEventType = responseBody.data;
|
||||||
expect(updatedEventType.title).toEqual(body.title);
|
expect(fetchedEventType.bookingFields).toEqual([]);
|
||||||
|
|
||||||
expect(updatedEventType.id).toEqual(eventType.id);
|
|
||||||
expect(updatedEventType.title).toEqual(newTitle);
|
|
||||||
expect(updatedEventType.description).toEqual(eventType.description);
|
|
||||||
expect(updatedEventType.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
|
||||||
expect(updatedEventType.locations).toEqual(eventType.locations);
|
|
||||||
expect(updatedEventType.bookingFields).toEqual(eventType.bookingFields);
|
|
||||||
expect(updatedEventType.ownerId).toEqual(user.id);
|
|
||||||
|
|
||||||
eventType.title = newTitle;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`/GET/:id`, async () => {
|
it("should return user created bookingFields among system fields in the database", async () => {
|
||||||
const response = await request(app.getHttpServer())
|
const userDefinedBookingField = {
|
||||||
.get(`/api/v2/event-types/${eventType.id}`)
|
name: "team",
|
||||||
|
type: "textarea",
|
||||||
|
label: "your team",
|
||||||
|
sources: [
|
||||||
|
{
|
||||||
|
id: "user",
|
||||||
|
type: "user",
|
||||||
|
label: "User",
|
||||||
|
fieldRequired: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
editable: "user",
|
||||||
|
required: true,
|
||||||
|
placeholder: "FC Barcelona",
|
||||||
|
};
|
||||||
|
|
||||||
|
const legacyEventTypeInput = {
|
||||||
|
title: "legacy event type two",
|
||||||
|
description: "legacy event type description two",
|
||||||
|
length: 40,
|
||||||
|
hidden: false,
|
||||||
|
slug: "legacy-event-type-two",
|
||||||
|
locations: [],
|
||||||
|
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||||
|
bookingFields: [
|
||||||
|
userDefinedBookingField,
|
||||||
|
{
|
||||||
|
name: "name",
|
||||||
|
type: "name",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system",
|
||||||
|
required: true,
|
||||||
|
defaultLabel: "your_name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "email",
|
||||||
|
type: "email",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system",
|
||||||
|
required: true,
|
||||||
|
defaultLabel: "email_address",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "location",
|
||||||
|
type: "radioInput",
|
||||||
|
label: "",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system",
|
||||||
|
required: false,
|
||||||
|
placeholder: "",
|
||||||
|
defaultLabel: "location",
|
||||||
|
getOptionsAt: "locations",
|
||||||
|
optionsInputs: {
|
||||||
|
phone: { type: "phone", required: true, placeholder: "" },
|
||||||
|
attendeeInPerson: { type: "address", required: true, placeholder: "" },
|
||||||
|
},
|
||||||
|
hideWhenJustOneOption: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "title",
|
||||||
|
type: "text",
|
||||||
|
hidden: true,
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: true,
|
||||||
|
defaultLabel: "what_is_this_meeting_about",
|
||||||
|
defaultPlaceholder: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "notes",
|
||||||
|
type: "textarea",
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: false,
|
||||||
|
defaultLabel: "additional_notes",
|
||||||
|
defaultPlaceholder: "share_additional_notes",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "guests",
|
||||||
|
type: "multiemail",
|
||||||
|
hidden: false,
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: false,
|
||||||
|
defaultLabel: "additional_guests",
|
||||||
|
defaultPlaceholder: "email",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rescheduleReason",
|
||||||
|
type: "textarea",
|
||||||
|
views: [{ id: "reschedule", label: "Reschedule View" }],
|
||||||
|
sources: [{ id: "default", type: "default", label: "Default" }],
|
||||||
|
editable: "system-but-optional",
|
||||||
|
required: false,
|
||||||
|
defaultLabel: "reason_for_reschedule",
|
||||||
|
defaultPlaceholder: "reschedule_placeholder",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const legacyEventType = await eventTypesRepositoryFixture.create(legacyEventTypeInput, user.id);
|
||||||
|
legacyEventTypeId2 = legacyEventType.id;
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.get(`/api/v2/event-types/${legacyEventTypeId2}`)
|
||||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||||
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
.expect(200)
|
||||||
.set("Authorization", `Bearer whatever`)
|
.then(async (response) => {
|
||||||
.expect(200);
|
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
||||||
|
const fetchedEventType = responseBody.data;
|
||||||
|
|
||||||
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
|
expect(fetchedEventType.bookingFields).toEqual([
|
||||||
const fetchedEventType = responseBody.data;
|
{
|
||||||
|
type: userDefinedBookingField.type,
|
||||||
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
slug: userDefinedBookingField.name,
|
||||||
expect(responseBody.data).toBeDefined();
|
label: userDefinedBookingField.label,
|
||||||
expect(fetchedEventType.id).toEqual(eventType.id);
|
required: userDefinedBookingField.required,
|
||||||
expect(fetchedEventType.title).toEqual(eventType.title);
|
placeholder: userDefinedBookingField.placeholder,
|
||||||
expect(fetchedEventType.description).toEqual(eventType.description);
|
},
|
||||||
expect(fetchedEventType.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
]);
|
||||||
expect(fetchedEventType.locations).toEqual(eventType.locations);
|
});
|
||||||
expect(fetchedEventType.bookingFields).toEqual(eventType.bookingFields);
|
|
||||||
expect(fetchedEventType.ownerId).toEqual(user.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`/GET/even-types by username`, async () => {
|
|
||||||
const response = await request(app.getHttpServer())
|
|
||||||
.get(`/api/v2/event-types?username=${username}`)
|
|
||||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
|
||||||
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
|
||||||
.set("Authorization", `Bearer whatever`)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14[]> = response.body;
|
|
||||||
|
|
||||||
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
|
||||||
expect(responseBody.data).toBeDefined();
|
|
||||||
expect(responseBody.data?.length).toEqual(1);
|
|
||||||
|
|
||||||
const fetchedEventType = responseBody.data?.[0];
|
|
||||||
|
|
||||||
expect(fetchedEventType?.id).toEqual(eventType.id);
|
|
||||||
expect(fetchedEventType?.title).toEqual(eventType.title);
|
|
||||||
expect(fetchedEventType?.description).toEqual(eventType.description);
|
|
||||||
expect(fetchedEventType?.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
|
||||||
expect(fetchedEventType?.locations).toEqual(eventType.locations);
|
|
||||||
expect(fetchedEventType?.bookingFields).toEqual(eventType.bookingFields);
|
|
||||||
expect(fetchedEventType?.ownerId).toEqual(user.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`/GET/event-types by username and eventSlug`, async () => {
|
|
||||||
const response = await request(app.getHttpServer())
|
|
||||||
.get(`/api/v2/event-types?username=${username}&eventSlug=${eventType.slug}`)
|
|
||||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
|
||||||
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
|
||||||
.set("Authorization", `Bearer whatever`)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14[]> = response.body;
|
|
||||||
const fetchedEventType = responseBody.data[0];
|
|
||||||
|
|
||||||
expect(fetchedEventType?.id).toEqual(eventType.id);
|
|
||||||
expect(fetchedEventType?.title).toEqual(eventType.title);
|
|
||||||
expect(fetchedEventType?.description).toEqual(eventType.description);
|
|
||||||
expect(fetchedEventType?.lengthInMinutes).toEqual(eventType.lengthInMinutes);
|
|
||||||
expect(fetchedEventType?.locations).toEqual(eventType.locations);
|
|
||||||
expect(fetchedEventType?.bookingFields).toEqual(eventType.bookingFields);
|
|
||||||
expect(fetchedEventType?.ownerId).toEqual(user.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`/GET/:id not existing`, async () => {
|
|
||||||
await request(app.getHttpServer())
|
|
||||||
.get(`/api/v2/event-types/1000`)
|
|
||||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
|
||||||
// note: bearer token value mocked using "withAccessTokenAuth" for user which id is used when creating event type above
|
|
||||||
.set("Authorization", `Bearer whatever`)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should delete schedule", async () => {
|
|
||||||
return request(app.getHttpServer()).delete(`/api/v2/event-types/${eventType.id}`).expect(200);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await oauthClientRepositoryFixture.delete(oAuthClient.id);
|
await oauthClientRepositoryFixture.delete(oAuthClient.id);
|
||||||
await teamRepositoryFixture.delete(organization.id);
|
await teamRepositoryFixture.delete(organization.id);
|
||||||
try {
|
try {
|
||||||
await eventTypesRepositoryFixture.delete(eventType.id);
|
await eventTypesRepositoryFixture.delete(legacyEventTypeId1);
|
||||||
|
await eventTypesRepositoryFixture.delete(legacyEventTypeId2);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Event type might have been deleted by the test
|
// Event type might have been deleted by the test
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { EventTypesRepository_2024_06_14 } from "@/ee/event-types/event-types_20
|
|||||||
import { EventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/event-types.service";
|
import { EventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/event-types.service";
|
||||||
import { InputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/input-event-types.service";
|
import { InputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/input-event-types.service";
|
||||||
import { OutputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/output-event-types.service";
|
import { OutputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/output-event-types.service";
|
||||||
|
import { SchedulesRepository_2024_06_11 } from "@/ee/schedules/schedules_2024_06_11/schedules.repository";
|
||||||
import { MembershipsModule } from "@/modules/memberships/memberships.module";
|
import { MembershipsModule } from "@/modules/memberships/memberships.module";
|
||||||
import { PrismaModule } from "@/modules/prisma/prisma.module";
|
import { PrismaModule } from "@/modules/prisma/prisma.module";
|
||||||
import { SelectedCalendarsModule } from "@/modules/selected-calendars/selected-calendars.module";
|
import { SelectedCalendarsModule } from "@/modules/selected-calendars/selected-calendars.module";
|
||||||
@@ -20,8 +21,14 @@ import { Module } from "@nestjs/common";
|
|||||||
OutputEventTypesService_2024_06_14,
|
OutputEventTypesService_2024_06_14,
|
||||||
UsersRepository,
|
UsersRepository,
|
||||||
UsersService,
|
UsersService,
|
||||||
|
SchedulesRepository_2024_06_11,
|
||||||
],
|
],
|
||||||
controllers: [EventTypesController_2024_06_14],
|
controllers: [EventTypesController_2024_06_14],
|
||||||
exports: [EventTypesService_2024_06_14, EventTypesRepository_2024_06_14],
|
exports: [
|
||||||
|
EventTypesService_2024_06_14,
|
||||||
|
EventTypesRepository_2024_06_14,
|
||||||
|
InputEventTypesService_2024_06_14,
|
||||||
|
OutputEventTypesService_2024_06_14,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class EventTypesModule_2024_06_14 {}
|
export class EventTypesModule_2024_06_14 {}
|
||||||
@@ -7,13 +7,24 @@ import {
|
|||||||
getEventTypeById,
|
getEventTypeById,
|
||||||
transformApiEventTypeBookingFields,
|
transformApiEventTypeBookingFields,
|
||||||
transformApiEventTypeLocations,
|
transformApiEventTypeLocations,
|
||||||
} from "@calcom/platform-libraries-0.0.18";
|
} from "@calcom/platform-libraries";
|
||||||
import { CreateEventTypeInput_2024_06_14 } from "@calcom/platform-types";
|
import { CreateEventTypeInput_2024_06_14 } from "@calcom/platform-types";
|
||||||
import type { PrismaClient } from "@calcom/prisma";
|
import type { PrismaClient } from "@calcom/prisma";
|
||||||
|
|
||||||
type InputEventTransformed = Omit<
|
type InputEventTransformed = Omit<
|
||||||
CreateEventTypeInput_2024_06_14,
|
CreateEventTypeInput_2024_06_14,
|
||||||
"lengthInMinutes" | "locations" | "bookingFields"
|
| "lengthInMinutes"
|
||||||
|
| "locations"
|
||||||
|
| "bookingFields"
|
||||||
|
| "bookingLimitsCount"
|
||||||
|
| "onlyShowFirstAvailableSlot"
|
||||||
|
| "bookingLimitsDuration"
|
||||||
|
| "offsetStart"
|
||||||
|
| "periodType"
|
||||||
|
| "periodDays"
|
||||||
|
| "periodCountCalendarDays"
|
||||||
|
| "periodStartDate"
|
||||||
|
| "periodEndDate"
|
||||||
> & {
|
> & {
|
||||||
length: number;
|
length: number;
|
||||||
slug: string;
|
slug: string;
|
||||||
|
|||||||
+55
-7
@@ -2,6 +2,7 @@ import { DEFAULT_EVENT_TYPES } from "@/ee/event-types/event-types_2024_06_14/con
|
|||||||
import { EventTypesRepository_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/event-types.repository";
|
import { EventTypesRepository_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/event-types.repository";
|
||||||
import { InputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/input-event-types.service";
|
import { InputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/input-event-types.service";
|
||||||
import { OutputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/output-event-types.service";
|
import { OutputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/output-event-types.service";
|
||||||
|
import { SchedulesRepository_2024_06_11 } from "@/ee/schedules/schedules_2024_06_11/schedules.repository";
|
||||||
import { MembershipsRepository } from "@/modules/memberships/memberships.repository";
|
import { MembershipsRepository } from "@/modules/memberships/memberships.repository";
|
||||||
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
|
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
|
||||||
import { SelectedCalendarsRepository } from "@/modules/selected-calendars/selected-calendars.repository";
|
import { SelectedCalendarsRepository } from "@/modules/selected-calendars/selected-calendars.repository";
|
||||||
@@ -9,9 +10,9 @@ import { UsersService } from "@/modules/users/services/users.service";
|
|||||||
import { UserWithProfile, UsersRepository } from "@/modules/users/users.repository";
|
import { UserWithProfile, UsersRepository } from "@/modules/users/users.repository";
|
||||||
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
||||||
|
|
||||||
import { createEventType, updateEventType } from "@calcom/platform-libraries-0.0.18";
|
import { createEventType, updateEventType } from "@calcom/platform-libraries";
|
||||||
import { getEventTypesPublic, EventTypesPublic } from "@calcom/platform-libraries-0.0.18";
|
import { getEventTypesPublic, EventTypesPublic } from "@calcom/platform-libraries";
|
||||||
import { dynamicEvent } from "@calcom/platform-libraries-0.0.18";
|
import { dynamicEvent } from "@calcom/platform-libraries";
|
||||||
import {
|
import {
|
||||||
CreateEventTypeInput_2024_06_14,
|
CreateEventTypeInput_2024_06_14,
|
||||||
UpdateEventTypeInput_2024_06_14,
|
UpdateEventTypeInput_2024_06_14,
|
||||||
@@ -30,13 +31,23 @@ export class EventTypesService_2024_06_14 {
|
|||||||
private readonly usersRepository: UsersRepository,
|
private readonly usersRepository: UsersRepository,
|
||||||
private readonly usersService: UsersService,
|
private readonly usersService: UsersService,
|
||||||
private readonly selectedCalendarsRepository: SelectedCalendarsRepository,
|
private readonly selectedCalendarsRepository: SelectedCalendarsRepository,
|
||||||
private readonly dbWrite: PrismaWriteService
|
private readonly dbWrite: PrismaWriteService,
|
||||||
|
private readonly schedulesRepository: SchedulesRepository_2024_06_11
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async createUserEventType(user: UserWithProfile, body: CreateEventTypeInput_2024_06_14) {
|
async createUserEventType(user: UserWithProfile, body: CreateEventTypeInput_2024_06_14) {
|
||||||
await this.checkCanCreateEventType(user.id, body);
|
await this.checkCanCreateEventType(user.id, body);
|
||||||
const eventTypeUser = await this.getUserToCreateEvent(user);
|
const eventTypeUser = await this.getUserToCreateEvent(user);
|
||||||
const bodyTransformed = this.inputEventTypesService.transformInputCreateEventType(body);
|
const {
|
||||||
|
bookingLimits,
|
||||||
|
durationLimits,
|
||||||
|
periodType = undefined,
|
||||||
|
periodDays = undefined,
|
||||||
|
periodCountCalendarDays = undefined,
|
||||||
|
periodStartDate = undefined,
|
||||||
|
periodEndDate = undefined,
|
||||||
|
...bodyTransformed
|
||||||
|
} = this.inputEventTypesService.transformInputCreateEventType(body);
|
||||||
const { eventType: eventTypeCreated } = await createEventType({
|
const { eventType: eventTypeCreated } = await createEventType({
|
||||||
input: bodyTransformed,
|
input: bodyTransformed,
|
||||||
ctx: {
|
ctx: {
|
||||||
@@ -47,6 +58,26 @@ export class EventTypesService_2024_06_14 {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await updateEventType({
|
||||||
|
input: {
|
||||||
|
id: eventTypeCreated.id,
|
||||||
|
bookingLimits,
|
||||||
|
durationLimits,
|
||||||
|
periodType,
|
||||||
|
periodDays,
|
||||||
|
periodCountCalendarDays,
|
||||||
|
periodStartDate,
|
||||||
|
periodEndDate,
|
||||||
|
...bodyTransformed,
|
||||||
|
},
|
||||||
|
ctx: {
|
||||||
|
user: eventTypeUser,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
prisma: this.dbWrite.prisma,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const eventType = await this.eventTypesRepository.getEventTypeById(eventTypeCreated.id);
|
const eventType = await this.eventTypesRepository.getEventTypeById(eventTypeCreated.id);
|
||||||
|
|
||||||
if (!eventType) {
|
if (!eventType) {
|
||||||
@@ -61,6 +92,7 @@ export class EventTypesService_2024_06_14 {
|
|||||||
if (existsWithSlug) {
|
if (existsWithSlug) {
|
||||||
throw new BadRequestException("User already has an event type with this slug.");
|
throw new BadRequestException("User already has an event type with this slug.");
|
||||||
}
|
}
|
||||||
|
await this.checkUserOwnsSchedule(userId, body.scheduleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEventTypeByUsernameAndSlug(username: string, eventTypeSlug: string) {
|
async getEventTypeByUsernameAndSlug(username: string, eventTypeSlug: string) {
|
||||||
@@ -92,13 +124,16 @@ export class EventTypesService_2024_06_14 {
|
|||||||
? await this.membershipsRepository.isUserOrganizationAdmin(user.id, organizationId)
|
? await this.membershipsRepository.isUserOrganizationAdmin(user.id, organizationId)
|
||||||
: false;
|
: false;
|
||||||
const profileId = user.movedToProfile?.id || null;
|
const profileId = user.movedToProfile?.id || null;
|
||||||
|
const selectedCalendars = await this.selectedCalendarsRepository.getUserSelectedCalendars(user.id);
|
||||||
return {
|
return {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
role: user.role,
|
role: user.role,
|
||||||
|
username: user.username,
|
||||||
organizationId: user.organizationId,
|
organizationId: user.organizationId,
|
||||||
organization: { isOrgAdmin },
|
organization: { isOrgAdmin },
|
||||||
profile: { id: profileId },
|
profile: { id: profileId },
|
||||||
metadata: user.metadata,
|
metadata: user.metadata,
|
||||||
|
selectedCalendars,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +238,7 @@ export class EventTypesService_2024_06_14 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateEventType(eventTypeId: number, body: UpdateEventTypeInput_2024_06_14, user: UserWithProfile) {
|
async updateEventType(eventTypeId: number, body: UpdateEventTypeInput_2024_06_14, user: UserWithProfile) {
|
||||||
this.checkCanUpdateEventType(user.id, eventTypeId);
|
await this.checkCanUpdateEventType(user.id, eventTypeId, body.scheduleId);
|
||||||
const eventTypeUser = await this.getUserToUpdateEvent(user);
|
const eventTypeUser = await this.getUserToUpdateEvent(user);
|
||||||
const bodyTransformed = this.inputEventTypesService.transformInputUpdateEventType(body);
|
const bodyTransformed = this.inputEventTypesService.transformInputUpdateEventType(body);
|
||||||
await updateEventType({
|
await updateEventType({
|
||||||
@@ -225,12 +260,13 @@ export class EventTypesService_2024_06_14 {
|
|||||||
return this.outputEventTypesService.getResponseEventType(user.id, eventType);
|
return this.outputEventTypesService.getResponseEventType(user.id, eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkCanUpdateEventType(userId: number, eventTypeId: number) {
|
async checkCanUpdateEventType(userId: number, eventTypeId: number, scheduleId: number | undefined) {
|
||||||
const existingEventType = await this.getUserEventType(userId, eventTypeId);
|
const existingEventType = await this.getUserEventType(userId, eventTypeId);
|
||||||
if (!existingEventType) {
|
if (!existingEventType) {
|
||||||
throw new NotFoundException(`Event type with id ${eventTypeId} not found`);
|
throw new NotFoundException(`Event type with id ${eventTypeId} not found`);
|
||||||
}
|
}
|
||||||
this.checkUserOwnsEventType(userId, { id: eventTypeId, userId: existingEventType.ownerId });
|
this.checkUserOwnsEventType(userId, { id: eventTypeId, userId: existingEventType.ownerId });
|
||||||
|
await this.checkUserOwnsSchedule(userId, scheduleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserToUpdateEvent(user: UserWithProfile) {
|
async getUserToUpdateEvent(user: UserWithProfile) {
|
||||||
@@ -255,4 +291,16 @@ export class EventTypesService_2024_06_14 {
|
|||||||
throw new ForbiddenException(`User with ID=${userId} does not own event type with ID=${eventType.id}`);
|
throw new ForbiddenException(`User with ID=${userId} does not own event type with ID=${eventType.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkUserOwnsSchedule(userId: number, scheduleId: number | null | undefined) {
|
||||||
|
if (!scheduleId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const schedule = await this.schedulesRepository.getScheduleByIdAndUserId(scheduleId, userId);
|
||||||
|
|
||||||
|
if (!schedule) {
|
||||||
|
throw new NotFoundException(`User with ID=${userId} does not own schedule with ID=${scheduleId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+43
-3
@@ -3,7 +3,9 @@ import { Injectable } from "@nestjs/common";
|
|||||||
import {
|
import {
|
||||||
transformApiEventTypeBookingFields,
|
transformApiEventTypeBookingFields,
|
||||||
transformApiEventTypeLocations,
|
transformApiEventTypeLocations,
|
||||||
} from "@calcom/platform-libraries-0.0.18";
|
transformApiEventTypeIntervalLimits,
|
||||||
|
transformApiEventTypeFutureBookingLimits,
|
||||||
|
} from "@calcom/platform-libraries";
|
||||||
import { CreateEventTypeInput_2024_06_14, UpdateEventTypeInput_2024_06_14 } from "@calcom/platform-types";
|
import { CreateEventTypeInput_2024_06_14, UpdateEventTypeInput_2024_06_14 } from "@calcom/platform-types";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -16,25 +18,54 @@ export class InputEventTypesService_2024_06_14 {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const { lengthInMinutes, locations, bookingFields, ...rest } = inputEventType;
|
const {
|
||||||
|
lengthInMinutes,
|
||||||
|
locations,
|
||||||
|
bookingFields,
|
||||||
|
bookingLimitsCount,
|
||||||
|
bookingLimitsDuration,
|
||||||
|
bookingWindow,
|
||||||
|
...rest
|
||||||
|
} = inputEventType;
|
||||||
|
|
||||||
const eventType = {
|
const eventType = {
|
||||||
...rest,
|
...rest,
|
||||||
length: lengthInMinutes,
|
length: lengthInMinutes,
|
||||||
locations: this.transformInputLocations(locations || defaultLocations),
|
locations: this.transformInputLocations(locations || defaultLocations),
|
||||||
bookingFields: this.transformInputBookingFields(bookingFields),
|
bookingFields: this.transformInputBookingFields(bookingFields),
|
||||||
|
bookingLimits: bookingLimitsCount ? this.transformInputIntervalLimits(bookingLimitsCount) : undefined,
|
||||||
|
durationLimits: bookingLimitsDuration
|
||||||
|
? this.transformInputIntervalLimits(bookingLimitsDuration)
|
||||||
|
: undefined,
|
||||||
|
...this.transformInputBookingWindow(bookingWindow),
|
||||||
};
|
};
|
||||||
|
|
||||||
return eventType;
|
return eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
transformInputUpdateEventType(inputEventType: UpdateEventTypeInput_2024_06_14) {
|
transformInputUpdateEventType(inputEventType: UpdateEventTypeInput_2024_06_14) {
|
||||||
const { locations, bookingFields, ...rest } = inputEventType;
|
const {
|
||||||
|
lengthInMinutes,
|
||||||
|
locations,
|
||||||
|
bookingFields,
|
||||||
|
scheduleId,
|
||||||
|
bookingLimitsCount,
|
||||||
|
bookingLimitsDuration,
|
||||||
|
bookingWindow,
|
||||||
|
...rest
|
||||||
|
} = inputEventType;
|
||||||
|
|
||||||
const eventType = {
|
const eventType = {
|
||||||
...rest,
|
...rest,
|
||||||
|
length: lengthInMinutes,
|
||||||
locations: locations ? this.transformInputLocations(locations) : undefined,
|
locations: locations ? this.transformInputLocations(locations) : undefined,
|
||||||
bookingFields: bookingFields ? this.transformInputBookingFields(bookingFields) : undefined,
|
bookingFields: bookingFields ? this.transformInputBookingFields(bookingFields) : undefined,
|
||||||
|
schedule: scheduleId,
|
||||||
|
bookingLimits: bookingLimitsCount ? this.transformInputIntervalLimits(bookingLimitsCount) : undefined,
|
||||||
|
durationLimits: bookingLimitsDuration
|
||||||
|
? this.transformInputIntervalLimits(bookingLimitsDuration)
|
||||||
|
: undefined,
|
||||||
|
...this.transformInputBookingWindow(bookingWindow),
|
||||||
};
|
};
|
||||||
|
|
||||||
return eventType;
|
return eventType;
|
||||||
@@ -47,4 +78,13 @@ export class InputEventTypesService_2024_06_14 {
|
|||||||
transformInputBookingFields(inputBookingFields: CreateEventTypeInput_2024_06_14["bookingFields"]) {
|
transformInputBookingFields(inputBookingFields: CreateEventTypeInput_2024_06_14["bookingFields"]) {
|
||||||
return transformApiEventTypeBookingFields(inputBookingFields);
|
return transformApiEventTypeBookingFields(inputBookingFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transformInputIntervalLimits(inputBookingFields: CreateEventTypeInput_2024_06_14["bookingLimitsCount"]) {
|
||||||
|
return transformApiEventTypeIntervalLimits(inputBookingFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
transformInputBookingWindow(inputBookingWindow: CreateEventTypeInput_2024_06_14["bookingWindow"]) {
|
||||||
|
const res = transformApiEventTypeFutureBookingLimits(inputBookingWindow);
|
||||||
|
return !!res ? res : {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+50
-11
@@ -9,7 +9,13 @@ import {
|
|||||||
parseRecurringEvent,
|
parseRecurringEvent,
|
||||||
TransformedLocationsSchema,
|
TransformedLocationsSchema,
|
||||||
BookingFieldsSchema,
|
BookingFieldsSchema,
|
||||||
} from "@calcom/platform-libraries-0.0.18";
|
SystemField,
|
||||||
|
UserField,
|
||||||
|
parseBookingLimit,
|
||||||
|
getResponseEventTypeIntervalLimits,
|
||||||
|
getResponseEventTypeFutureBookingLimits,
|
||||||
|
} from "@calcom/platform-libraries";
|
||||||
|
import { TransformFutureBookingsLimitSchema_2024_06_14 } from "@calcom/platform-types";
|
||||||
|
|
||||||
type EventTypeRelations = { users: User[]; schedule: Schedule | null };
|
type EventTypeRelations = { users: User[]; schedule: Schedule | null };
|
||||||
type DatabaseEventType = EventType & EventTypeRelations;
|
type DatabaseEventType = EventType & EventTypeRelations;
|
||||||
@@ -41,7 +47,16 @@ type Input = Pick<
|
|||||||
| "recurringEvent"
|
| "recurringEvent"
|
||||||
| "metadata"
|
| "metadata"
|
||||||
| "users"
|
| "users"
|
||||||
| "schedule"
|
| "scheduleId"
|
||||||
|
| "bookingLimits"
|
||||||
|
| "durationLimits"
|
||||||
|
| "onlyShowFirstAvailableSlot"
|
||||||
|
| "offsetStart"
|
||||||
|
| "periodType"
|
||||||
|
| "periodDays"
|
||||||
|
| "periodCountCalendarDays"
|
||||||
|
| "periodStartDate"
|
||||||
|
| "periodEndDate"
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -68,14 +83,27 @@ export class OutputEventTypesService_2024_06_14 {
|
|||||||
successRedirectUrl,
|
successRedirectUrl,
|
||||||
seatsShowAvailabilityCount,
|
seatsShowAvailabilityCount,
|
||||||
isInstantEvent,
|
isInstantEvent,
|
||||||
|
scheduleId,
|
||||||
|
onlyShowFirstAvailableSlot,
|
||||||
|
offsetStart,
|
||||||
} = databaseEventType;
|
} = databaseEventType;
|
||||||
|
|
||||||
const locations = this.transformLocations(databaseEventType.locations);
|
const locations = this.transformLocations(databaseEventType.locations);
|
||||||
const bookingFields = this.transformBookingFields(databaseEventType.bookingFields);
|
const bookingFields = databaseEventType.bookingFields
|
||||||
|
? this.transformBookingFields(BookingFieldsSchema.parse(databaseEventType.bookingFields))
|
||||||
|
: [];
|
||||||
const recurringEvent = this.transformRecurringEvent(databaseEventType.recurringEvent);
|
const recurringEvent = this.transformRecurringEvent(databaseEventType.recurringEvent);
|
||||||
const metadata = this.transformMetadata(databaseEventType.metadata) || {};
|
const metadata = this.transformMetadata(databaseEventType.metadata) || {};
|
||||||
const schedule = await this.getSchedule(databaseEventType);
|
|
||||||
const users = this.transformUsers(databaseEventType.users);
|
const users = this.transformUsers(databaseEventType.users);
|
||||||
|
const bookingLimitsCount = this.transformIntervalLimits(databaseEventType.bookingLimits);
|
||||||
|
const bookingLimitsDuration = this.transformIntervalLimits(databaseEventType.durationLimits);
|
||||||
|
const bookingWindow = this.transformBookingWindow({
|
||||||
|
periodType: databaseEventType.periodType,
|
||||||
|
periodDays: databaseEventType.periodDays,
|
||||||
|
periodCountCalendarDays: databaseEventType.periodCountCalendarDays,
|
||||||
|
periodStartDate: databaseEventType.periodStartDate,
|
||||||
|
periodEndDate: databaseEventType.periodEndDate,
|
||||||
|
} as TransformFutureBookingsLimitSchema_2024_06_14);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
@@ -104,7 +132,12 @@ export class OutputEventTypesService_2024_06_14 {
|
|||||||
seatsShowAvailabilityCount,
|
seatsShowAvailabilityCount,
|
||||||
isInstantEvent,
|
isInstantEvent,
|
||||||
users,
|
users,
|
||||||
schedule,
|
scheduleId,
|
||||||
|
bookingLimitsCount,
|
||||||
|
bookingLimitsDuration,
|
||||||
|
onlyShowFirstAvailableSlot,
|
||||||
|
offsetStart,
|
||||||
|
bookingWindow,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,9 +146,10 @@ export class OutputEventTypesService_2024_06_14 {
|
|||||||
return getResponseEventTypeLocations(TransformedLocationsSchema.parse(locations));
|
return getResponseEventTypeLocations(TransformedLocationsSchema.parse(locations));
|
||||||
}
|
}
|
||||||
|
|
||||||
transformBookingFields(inputBookingFields: any) {
|
transformBookingFields(inputBookingFields: (SystemField | UserField)[] | null) {
|
||||||
if (!inputBookingFields) return [];
|
if (!inputBookingFields) return [];
|
||||||
return getResponseEventTypeBookingFields(BookingFieldsSchema.parse(inputBookingFields));
|
const userFields = inputBookingFields.filter((field) => field.editable === "user") as UserField[];
|
||||||
|
return getResponseEventTypeBookingFields(userFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
transformRecurringEvent(recurringEvent: any) {
|
transformRecurringEvent(recurringEvent: any) {
|
||||||
@@ -128,10 +162,6 @@ export class OutputEventTypesService_2024_06_14 {
|
|||||||
return EventTypeMetaDataSchema.parse(metadata);
|
return EventTypeMetaDataSchema.parse(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSchedule(databaseEventType: Input) {
|
|
||||||
return databaseEventType.schedule || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
transformUsers(users: User[]) {
|
transformUsers(users: User[]) {
|
||||||
return users.map((user) => {
|
return users.map((user) => {
|
||||||
const metadata = user.metadata ? userMetadata.parse(user.metadata) : {};
|
const metadata = user.metadata ? userMetadata.parse(user.metadata) : {};
|
||||||
@@ -147,4 +177,13 @@ export class OutputEventTypesService_2024_06_14 {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transformIntervalLimits(bookingLimits: any) {
|
||||||
|
const bookingLimitsParsed = parseBookingLimit(bookingLimits);
|
||||||
|
return getResponseEventTypeIntervalLimits(bookingLimitsParsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
transformBookingWindow(bookingLimits: TransformFutureBookingsLimitSchema_2024_06_14) {
|
||||||
|
return getResponseEventTypeFutureBookingLimits(bookingLimits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { CalendarsRepository } from "@/ee/calendars/calendars.repository";
|
||||||
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
||||||
import { GcalController } from "@/ee/gcal/gcal.controller";
|
import { GcalController } from "@/ee/gcal/gcal.controller";
|
||||||
import { AppsRepository } from "@/modules/apps/apps.repository";
|
import { AppsRepository } from "@/modules/apps/apps.repository";
|
||||||
@@ -21,6 +22,7 @@ import { ConfigService } from "@nestjs/config";
|
|||||||
GCalService,
|
GCalService,
|
||||||
CalendarsService,
|
CalendarsService,
|
||||||
UsersRepository,
|
UsersRepository,
|
||||||
|
CalendarsRepository,
|
||||||
],
|
],
|
||||||
controllers: [GcalController],
|
controllers: [GcalController],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import { UsersModule } from "@/modules/users/users.module";
|
|||||||
import { INestApplication } from "@nestjs/common";
|
import { INestApplication } from "@nestjs/common";
|
||||||
import { NestExpressApplication } from "@nestjs/platform-express";
|
import { NestExpressApplication } from "@nestjs/platform-express";
|
||||||
import { Test } from "@nestjs/testing";
|
import { Test } from "@nestjs/testing";
|
||||||
import { User } from "@prisma/client";
|
import { User, Team } from "@prisma/client";
|
||||||
import * as request from "supertest";
|
import * as request from "supertest";
|
||||||
|
import { OrganizationRepositoryFixture } from "test/fixtures/repository/organization.repository.fixture";
|
||||||
|
import { ProfileRepositoryFixture } from "test/fixtures/repository/profiles.repository.fixture";
|
||||||
import { SchedulesRepositoryFixture } from "test/fixtures/repository/schedules.repository.fixture";
|
import { SchedulesRepositoryFixture } from "test/fixtures/repository/schedules.repository.fixture";
|
||||||
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
|
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
|
||||||
import { withApiAuth } from "test/utils/withApiAuth";
|
import { withApiAuth } from "test/utils/withApiAuth";
|
||||||
@@ -25,9 +27,11 @@ describe("Me Endpoints", () => {
|
|||||||
|
|
||||||
let userRepositoryFixture: UserRepositoryFixture;
|
let userRepositoryFixture: UserRepositoryFixture;
|
||||||
let schedulesRepositoryFixture: SchedulesRepositoryFixture;
|
let schedulesRepositoryFixture: SchedulesRepositoryFixture;
|
||||||
|
let profilesRepositoryFixture: ProfileRepositoryFixture;
|
||||||
|
let organizationsRepositoryFixture: OrganizationRepositoryFixture;
|
||||||
const userEmail = "me-controller-e2e@api.com";
|
const userEmail = "me-controller-e2e@api.com";
|
||||||
let user: User;
|
let user: User;
|
||||||
|
let org: Team;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const moduleRef = await withApiAuth(
|
const moduleRef = await withApiAuth(
|
||||||
@@ -43,6 +47,9 @@ describe("Me Endpoints", () => {
|
|||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
userRepositoryFixture = new UserRepositoryFixture(moduleRef);
|
userRepositoryFixture = new UserRepositoryFixture(moduleRef);
|
||||||
|
organizationsRepositoryFixture = new OrganizationRepositoryFixture(moduleRef);
|
||||||
|
profilesRepositoryFixture = new ProfileRepositoryFixture(moduleRef);
|
||||||
|
|
||||||
schedulesRepositoryFixture = new SchedulesRepositoryFixture(moduleRef);
|
schedulesRepositoryFixture = new SchedulesRepositoryFixture(moduleRef);
|
||||||
|
|
||||||
user = await userRepositoryFixture.create({
|
user = await userRepositoryFixture.create({
|
||||||
@@ -50,6 +57,20 @@ describe("Me Endpoints", () => {
|
|||||||
username: userEmail,
|
username: userEmail,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
org = await organizationsRepositoryFixture.create({
|
||||||
|
name: "Test org team",
|
||||||
|
isOrganization: true,
|
||||||
|
isPlatform: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await profilesRepositoryFixture.create({
|
||||||
|
uid: "asd-asd",
|
||||||
|
username: userEmail,
|
||||||
|
user: { connect: { id: user.id } },
|
||||||
|
organization: { connect: { id: org.id } },
|
||||||
|
movedFromUser: { connect: { id: user.id } },
|
||||||
|
});
|
||||||
|
|
||||||
app = moduleRef.createNestApplication();
|
app = moduleRef.createNestApplication();
|
||||||
bootstrap(app as NestExpressApplication);
|
bootstrap(app as NestExpressApplication);
|
||||||
|
|
||||||
@@ -75,6 +96,8 @@ describe("Me Endpoints", () => {
|
|||||||
expect(responseBody.data.defaultScheduleId).toEqual(user.defaultScheduleId);
|
expect(responseBody.data.defaultScheduleId).toEqual(user.defaultScheduleId);
|
||||||
expect(responseBody.data.weekStart).toEqual(user.weekStart);
|
expect(responseBody.data.weekStart).toEqual(user.weekStart);
|
||||||
expect(responseBody.data.timeZone).toEqual(user.timeZone);
|
expect(responseBody.data.timeZone).toEqual(user.timeZone);
|
||||||
|
expect(responseBody.data.organization?.isPlatform).toEqual(true);
|
||||||
|
expect(responseBody.data.organization?.id).toEqual(org.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,6 +126,21 @@ describe("Me Endpoints", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should update user associated with access token given badly formatted timezone", async () => {
|
||||||
|
const bodyWithBadlyFormattedTimeZone: UpdateManagedUserInput = { timeZone: "America/New_york" };
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.patch("/v2/me")
|
||||||
|
.send(bodyWithBadlyFormattedTimeZone)
|
||||||
|
.expect(200)
|
||||||
|
.then(async (response) => {
|
||||||
|
const responseBody: ApiSuccessResponse<UserResponse> = response.body;
|
||||||
|
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
||||||
|
|
||||||
|
expect(responseBody.data.timeZone).toEqual("America/New_York");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should not update user associated with access token given invalid timezone", async () => {
|
it("should not update user associated with access token given invalid timezone", async () => {
|
||||||
const bodyWithIncorrectTimeZone: UpdateManagedUserInput = { timeZone: "Narnia/Woods" };
|
const bodyWithIncorrectTimeZone: UpdateManagedUserInput = { timeZone: "Narnia/Woods" };
|
||||||
|
|
||||||
@@ -123,6 +161,7 @@ describe("Me Endpoints", () => {
|
|||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await userRepositoryFixture.deleteByEmail(user.email);
|
await userRepositoryFixture.deleteByEmail(user.email);
|
||||||
|
await organizationsRepositoryFixture.delete(org.id);
|
||||||
await app.close();
|
await app.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Permissions } from "@/modules/auth/decorators/permissions/permissions.d
|
|||||||
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard";
|
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard";
|
||||||
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
|
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
|
||||||
import { UpdateManagedUserInput } from "@/modules/users/inputs/update-managed-user.input";
|
import { UpdateManagedUserInput } from "@/modules/users/inputs/update-managed-user.input";
|
||||||
|
import { UsersService } from "@/modules/users/services/users.service";
|
||||||
import { UserWithProfile, UsersRepository } from "@/modules/users/users.repository";
|
import { UserWithProfile, UsersRepository } from "@/modules/users/users.repository";
|
||||||
import { Controller, UseGuards, Get, Patch, Body } from "@nestjs/common";
|
import { Controller, UseGuards, Get, Patch, Body } from "@nestjs/common";
|
||||||
import { ApiTags as DocsTags } from "@nestjs/swagger";
|
import { ApiTags as DocsTags } from "@nestjs/swagger";
|
||||||
@@ -23,14 +24,26 @@ import { userSchemaResponse } from "@calcom/platform-types";
|
|||||||
export class MeController {
|
export class MeController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly usersRepository: UsersRepository,
|
private readonly usersRepository: UsersRepository,
|
||||||
private readonly schedulesRepository: SchedulesService_2024_04_15
|
private readonly schedulesService: SchedulesService_2024_04_15,
|
||||||
|
private readonly usersService: UsersService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get("/")
|
@Get("/")
|
||||||
@Permissions([PROFILE_READ])
|
@Permissions([PROFILE_READ])
|
||||||
async getMe(@GetUser() user: UserWithProfile): Promise<GetMeOutput> {
|
async getMe(@GetUser() user: UserWithProfile): Promise<GetMeOutput> {
|
||||||
const me = userSchemaResponse.parse(user);
|
const organization = this.usersService.getUserMainProfile(user)?.organization;
|
||||||
|
const me = userSchemaResponse.parse(
|
||||||
|
organization
|
||||||
|
? {
|
||||||
|
...user,
|
||||||
|
organizationId: organization.id,
|
||||||
|
organization: {
|
||||||
|
id: organization.id,
|
||||||
|
isPlatform: organization.isPlatform,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: user
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
status: SUCCESS_STATUS,
|
status: SUCCESS_STATUS,
|
||||||
data: me,
|
data: me,
|
||||||
@@ -45,7 +58,7 @@ export class MeController {
|
|||||||
): Promise<UpdateMeOutput> {
|
): Promise<UpdateMeOutput> {
|
||||||
const updatedUser = await this.usersRepository.update(user.id, bodySchedule);
|
const updatedUser = await this.usersRepository.update(user.id, bodySchedule);
|
||||||
if (bodySchedule.timeZone && user.defaultScheduleId) {
|
if (bodySchedule.timeZone && user.defaultScheduleId) {
|
||||||
await this.schedulesRepository.updateUserSchedule(user, user.defaultScheduleId, {
|
await this.schedulesService.updateUserSchedule(user, user.defaultScheduleId, {
|
||||||
timeZone: bodySchedule.timeZone,
|
timeZone: bodySchedule.timeZone,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { IsInt, IsEmail, IsOptional, IsString } from "class-validator";
|
import { Type } from "class-transformer";
|
||||||
|
import { IsInt, IsEmail, IsOptional, IsString, ValidateNested } from "class-validator";
|
||||||
|
|
||||||
|
export class MeOrgOutput {
|
||||||
|
isPlatform!: boolean;
|
||||||
|
|
||||||
|
id!: number;
|
||||||
|
}
|
||||||
export class MeOutput {
|
export class MeOutput {
|
||||||
@IsInt()
|
@IsInt()
|
||||||
id!: number;
|
id!: number;
|
||||||
@@ -22,4 +28,12 @@ export class MeOutput {
|
|||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
timeZone!: string;
|
timeZone!: string;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
organizationId!: number | null;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@ValidateNested()
|
||||||
|
@Type(() => MeOrgOutput)
|
||||||
|
organization?: MeOrgOutput;
|
||||||
}
|
}
|
||||||
+31
@@ -66,6 +66,37 @@ describe("Schedules Endpoints", () => {
|
|||||||
expect(user).toBeDefined();
|
expect(user).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not create an invalid schedule", async () => {
|
||||||
|
const scheduleName = "schedule-name";
|
||||||
|
const scheduleTimeZone = "Europe/Rome";
|
||||||
|
const isDefault = true;
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
name: scheduleName,
|
||||||
|
timeZone: scheduleTimeZone,
|
||||||
|
isDefault,
|
||||||
|
availabilities: [
|
||||||
|
{
|
||||||
|
days: ["Monday"],
|
||||||
|
endTime: "11:15",
|
||||||
|
startTime: "10:00",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.post("/api/v2/schedules")
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
|
||||||
|
.send(body)
|
||||||
|
.expect(400)
|
||||||
|
.then(async (response) => {
|
||||||
|
expect(response.body.status).toEqual("error");
|
||||||
|
expect(response.body.error.message).toEqual(
|
||||||
|
"Invalid datestring format. Expected format(ISO8061): 2025-04-12T13:17:56.324Z. Received: 11:15"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should create a default schedule", async () => {
|
it("should create a default schedule", async () => {
|
||||||
const scheduleName = "schedule-name";
|
const scheduleName = "schedule-name";
|
||||||
const scheduleTimeZone = "Europe/Rome";
|
const scheduleTimeZone = "Europe/Rome";
|
||||||
|
|||||||
+11
-1
@@ -19,8 +19,18 @@ export class CreateAvailabilityInput_2024_04_15 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function transformStringToDate(value: string, key: string): Date {
|
function transformStringToDate(value: string, key: string): Date {
|
||||||
// note(Lauris): incoming value is ISO8061 e.g. 2025-0412T13:17:56.324Z
|
if (!value) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`Missing ${key}. Expected value is in ISO8061 format e.g. 2025-0412T13:17:56.324Z`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const dateTimeParts = value.split("T");
|
const dateTimeParts = value.split("T");
|
||||||
|
if (dateTimeParts.length !== 2) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`Invalid datestring format. Expected format(ISO8061): 2025-04-12T13:17:56.324Z. Received: ${value}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const timePart = dateTimeParts[1].split(".")[0]; // Removes milliseconds
|
const timePart = dateTimeParts[1].split(".")[0]; // Removes milliseconds
|
||||||
const parts = timePart.split(":");
|
const parts = timePart.split(":");
|
||||||
|
|||||||
Loaded 100 of 872 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user