-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e10fe1a
commit 8c826fc
Showing
13 changed files
with
321 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
describe('Dashboard page', () => { | ||
before(() => { | ||
cy.intercept({ | ||
url: 'https://s3.eu-west-3.amazonaws.com/typebot', | ||
method: 'POST', | ||
}).as('postImage') | ||
cy.intercept({ url: '/api/auth/session?update', method: 'GET' }).as( | ||
'getUpdatedSession' | ||
) | ||
}) | ||
|
||
beforeEach(() => { | ||
cy.task('seed') | ||
cy.signOut() | ||
}) | ||
|
||
it('should edit user info properly', () => { | ||
cy.signIn('test1@gmail.com') | ||
cy.visit('/account') | ||
cy.findByRole('button', { name: 'Save' }).should('not.exist') | ||
cy.findByRole('textbox', { name: 'Email address' }).should( | ||
'have.attr', | ||
'disabled' | ||
) | ||
cy.findByRole('textbox', { name: 'Name' }) | ||
.should('have.value', '') | ||
.type('John Doe') | ||
|
||
cy.findByRole('img').should('not.have.attr', 'src') | ||
cy.findByLabelText('Change photo').attachFile('avatar.jpg') | ||
cy.wait('@postImage') | ||
cy.findByRole('img') | ||
.should('have.attr', 'src') | ||
.should( | ||
'include', | ||
'https://s3.eu-west-3.amazonaws.com/typebot/test1/avatar' | ||
) | ||
cy.findByRole('button', { name: 'Save' }).should('exist').click() | ||
cy.wait('@getUpdatedSession') | ||
cy.reload() | ||
cy.findByRole('textbox', { name: 'Name' }).should('have.value', 'John Doe') | ||
cy.findByRole('img') | ||
.should('have.attr', 'src') | ||
.should( | ||
'include', | ||
'https://s3.eu-west-3.amazonaws.com/typebot/test1/avatar' | ||
) | ||
cy.findByRole('button', { name: 'Save' }).should('not.exist') | ||
}) | ||
|
||
it('should display valid plans', () => { | ||
cy.signIn('test1@gmail.com') | ||
cy.visit('/account') | ||
cy.findByText('Free plan').should('exist') | ||
cy.findByRole('link', { name: 'Manage my subscription' }).should( | ||
'not.exist' | ||
) | ||
cy.findByRole('button', { name: 'Upgrade' }).should('exist') | ||
cy.signOut() | ||
cy.signIn('test2@gmail.com') | ||
cy.visit('/account') | ||
cy.findByText('Pro plan').should('exist') | ||
cy.findByRole('link', { name: 'Manage my subscription' }) | ||
.should('have.attr', 'href') | ||
.should('include', 'customer-portal') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { User } from 'db' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getSession } from 'next-auth/react' | ||
import { methodNotAllowed } from 'services/api/utils' | ||
import Stripe from 'stripe' | ||
|
||
const createCheckoutSession = async ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) => { | ||
const session = await getSession({ req }) | ||
if (!session?.user) | ||
return res.status(401).json({ message: 'Not authenticated' }) | ||
const user = session.user as User | ||
if (!user.stripeId) | ||
return res.status(401).json({ message: 'Not authenticated' }) | ||
if (req.method === 'GET') { | ||
if (!process.env.STRIPE_SECRET_KEY) | ||
throw Error('STRIPE_SECRET_KEY var is missing') | ||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { | ||
apiVersion: '2020-08-27', | ||
}) | ||
const session = await stripe.billingPortal.sessions.create({ | ||
customer: user.stripeId, | ||
return_url: `${req.headers.origin}/account`, | ||
}) | ||
res.status(201).redirect(session.url) | ||
} | ||
return methodNotAllowed(res) | ||
} | ||
|
||
export default createCheckoutSession |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './components/TypebotViewer' | ||
export * from './models' | ||
export { parseNewTypebot } from './services/utils' |
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,7 +1,55 @@ | ||
import { Step, TextStep, StepType, TextInputStep } from '../models' | ||
import { Prisma } from 'db' | ||
import { | ||
Step, | ||
TextStep, | ||
StepType, | ||
TextInputStep, | ||
BackgroundType, | ||
Settings, | ||
StartBlock, | ||
Theme, | ||
} from '../models' | ||
|
||
export const isTextStep = (step: Step): step is TextStep => | ||
step.type === StepType.TEXT | ||
|
||
export const isTextInputStep = (step: Step): step is TextInputStep => | ||
step.type === StepType.TEXT_INPUT | ||
|
||
export const parseNewTypebot = ({ | ||
ownerId, | ||
folderId, | ||
name, | ||
}: { | ||
ownerId: string | ||
folderId: string | null | ||
name: string | ||
}): Prisma.TypebotUncheckedCreateInput => { | ||
const startBlock: StartBlock = { | ||
id: 'start-block', | ||
title: 'Start', | ||
graphCoordinates: { x: 0, y: 0 }, | ||
steps: [ | ||
{ | ||
id: 'start-step', | ||
blockId: 'start-block', | ||
label: 'Form starts here', | ||
type: StepType.START, | ||
}, | ||
], | ||
} | ||
const theme: Theme = { | ||
general: { | ||
font: 'Open Sans', | ||
background: { type: BackgroundType.NONE, content: '#ffffff' }, | ||
}, | ||
} | ||
const settings: Settings = { | ||
typingEmulation: { | ||
enabled: true, | ||
speed: 300, | ||
maxDelay: 1.5, | ||
}, | ||
} | ||
return { folderId, name, ownerId, startBlock, theme, settings } | ||
} |
Oops, something went wrong.