Skip to content

Commit 751c36a

Browse files
authored
fix(airtable): fixed airtable oauth token refresh, added tests (#502)
* fixed airtable token refresh, added tests * added helpers for refreshOAuthToken function
1 parent a2a131c commit 751c36a

File tree

17 files changed

+609
-169
lines changed

17 files changed

+609
-169
lines changed

apps/sim/app/api/auth/oauth/credentials/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { jwtDecode } from 'jwt-decode'
33
import { type NextRequest, NextResponse } from 'next/server'
44
import { getSession } from '@/lib/auth'
55
import { createLogger } from '@/lib/logs/console-logger'
6-
import type { OAuthService } from '@/lib/oauth'
7-
import { parseProvider } from '@/lib/oauth'
6+
import type { OAuthService } from '@/lib/oauth/oauth'
7+
import { parseProvider } from '@/lib/oauth/oauth'
88
import { db } from '@/db'
99
import { account, user } from '@/db/schema'
1010

apps/sim/app/api/auth/oauth/utils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('OAuth Utils', () => {
3535
db: mockDb,
3636
}))
3737

38-
vi.doMock('@/lib/oauth', () => ({
38+
vi.doMock('@/lib/oauth/oauth', () => ({
3939
refreshOAuthToken: mockRefreshOAuthToken,
4040
}))
4141

@@ -181,13 +181,13 @@ describe('OAuth Utils', () => {
181181
providerId: 'google',
182182
}
183183

184-
mockRefreshOAuthToken.mockRejectedValueOnce(new Error('Refresh failed'))
184+
mockRefreshOAuthToken.mockResolvedValueOnce(null)
185185

186186
const { refreshTokenIfNeeded } = await import('./utils')
187187

188188
await expect(
189189
refreshTokenIfNeeded('request-id', mockCredential, 'credential-id')
190-
).rejects.toThrow()
190+
).rejects.toThrow('Failed to refresh token')
191191

192192
expect(mockLogger.error).toHaveBeenCalled()
193193
})

apps/sim/app/api/auth/oauth/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { and, eq } from 'drizzle-orm'
22
import { getSession } from '@/lib/auth'
33
import { createLogger } from '@/lib/logs/console-logger'
4-
import { refreshOAuthToken } from '@/lib/oauth'
4+
import { refreshOAuthToken } from '@/lib/oauth/oauth'
55
import { db } from '@/db'
66
import { account, workflow } from '@/db/schema'
77

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/credential-selector/components/oauth-required-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
OAUTH_PROVIDERS,
1919
type OAuthProvider,
2020
parseProvider,
21-
} from '@/lib/oauth'
21+
} from '@/lib/oauth/oauth'
2222
import { saveToStorage } from '@/stores/workflows/persistence'
2323

2424
const logger = createLogger('OAuthRequiredModal')

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/credential-selector/credential-selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
OAUTH_PROVIDERS,
2121
type OAuthProvider,
2222
parseProvider,
23-
} from '@/lib/oauth'
23+
} from '@/lib/oauth/oauth'
2424
import { saveToStorage } from '@/stores/workflows/persistence'
2525
import { OAuthRequiredModal } from './components/oauth-required-modal'
2626

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/confluence-file-selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
getProviderIdFromServiceId,
1919
getServiceIdFromScopes,
2020
type OAuthProvider,
21-
} from '@/lib/oauth'
21+
} from '@/lib/oauth/oauth'
2222
import { saveToStorage } from '@/stores/workflows/persistence'
2323
import { OAuthRequiredModal } from '../../credential-selector/components/oauth-required-modal'
2424

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/google-drive-picker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
OAUTH_PROVIDERS,
2424
type OAuthProvider,
2525
parseProvider,
26-
} from '@/lib/oauth'
26+
} from '@/lib/oauth/oauth'
2727
import { saveToStorage } from '@/stores/workflows/persistence'
2828
import { OAuthRequiredModal } from '../../credential-selector/components/oauth-required-modal'
2929

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/jira-issue-selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
getProviderIdFromServiceId,
2020
getServiceIdFromScopes,
2121
type OAuthProvider,
22-
} from '@/lib/oauth'
22+
} from '@/lib/oauth/oauth'
2323
import { saveToStorage } from '@/stores/workflows/persistence'
2424
import { OAuthRequiredModal } from '../../credential-selector/components/oauth-required-modal'
2525

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/microsoft-file-selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
OAUTH_PROVIDERS,
2323
type OAuthProvider,
2424
parseProvider,
25-
} from '@/lib/oauth'
25+
} from '@/lib/oauth/oauth'
2626
import { saveToStorage } from '@/stores/workflows/persistence'
2727
import { OAuthRequiredModal } from '../../credential-selector/components/oauth-required-modal'
2828

apps/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/teams-message-selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
getProviderIdFromServiceId,
2020
getServiceIdFromScopes,
2121
type OAuthProvider,
22-
} from '@/lib/oauth'
22+
} from '@/lib/oauth/oauth'
2323
import { saveToStorage } from '@/stores/workflows/persistence'
2424
import { OAuthRequiredModal } from '../../credential-selector/components/oauth-required-modal'
2525

0 commit comments

Comments
 (0)