-
Notifications
You must be signed in to change notification settings - Fork 973
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't create an AuthProvider if one exists (#1251)
* Don't create an AuthProvider if one exists * Handle --force flag * Remove old auth provider imports * Fix broken test * Make variable for existing auth provider error * Fix formatting with Prettier * Handle GraphQL import * Make sure web imports are included * Handle null regex match Co-authored-by: David Price <thedavid@thedavidprice.com>
- Loading branch information
1 parent
e69bb0b
commit 0ba96d8
Showing
4 changed files
with
130 additions
and
24 deletions.
There are no files selected for viewing
46 changes: 42 additions & 4 deletions
46
packages/cli/src/commands/generate/auth/__tests__/auth.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
global.__dirname = __dirname | ||
// import { loadGeneratorFixture } from 'src/lib/test' | ||
|
||
// import * as auth from '../auth' | ||
import { | ||
waitFor, | ||
} from '@testing-library/react' | ||
|
||
test('true', () => { | ||
expect(true).toEqual(true) | ||
jest.mock('fs') | ||
jest.mock('src/lib', () => ({ | ||
getPaths: () => ({ | ||
api: { functions: '', src: '', lib: '' }, | ||
web: { src: '' }, | ||
}), | ||
})) | ||
|
||
import fs from 'fs' | ||
import chalk from 'chalk' | ||
|
||
import * as auth from '../auth' | ||
|
||
const EXISTING_AUTH_PROVIDER_ERROR = 'Existing auth provider found.\nUse --force to override existing provider.'; | ||
|
||
test(`no error thrown when auth provider not found`, async () => { | ||
// Mock process.exit to make sure CLI quites | ||
const cSpy = jest.spyOn(console, 'log').mockImplementation(() => {}) | ||
|
||
auth.handler({ provider: 'netlify' }) | ||
await waitFor(() => expect(console.log).toHaveBeenCalledTimes(1)) | ||
expect(console.log).not.toHaveBeenCalledWith(chalk.bold.red(EXISTING_AUTH_PROVIDER_ERROR)) | ||
|
||
// Restore mocks | ||
cSpy.mockRestore() | ||
}) | ||
|
||
test('throws an error if auth provider exists', async () => { | ||
// Mock process.exit to make sure CLI quites | ||
const fsSpy = jest.spyOn(fs, 'readFileSync').mockImplementation(() => `import { AuthProvider } from '@redwoodjs/auth'`) | ||
const cSpy = jest.spyOn(console, 'log').mockImplementation(() => {}) | ||
|
||
auth.handler({ provider: 'netlify' }) | ||
await waitFor(() => expect(console.log).toHaveBeenCalledTimes(1)) | ||
expect(console.log).toHaveBeenCalledWith(chalk.bold.red(EXISTING_AUTH_PROVIDER_ERROR)) | ||
|
||
// Restore mocks | ||
fsSpy.mockRestore() | ||
cSpy.mockRestore() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters