Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

131 add feature tests #149

Merged
merged 30 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9d9ba72
add key perk to landing page (#107)
leilabb Jan 12, 2024
37f8a60
98-clarify-copy-when-creating-a-team
leilabb Jan 16, 2024
b8032f3
104-change-the-word-fork-it-to-clone-including-icon
leilabb Jan 19, 2024
ce0b05d
add missing env vars to example
tonioriol Jan 22, 2024
1d5d352
Create dependabot.yml
eriklindgren Jan 22, 2024
de85015
Bump vite from 4.3.9 to 4.5.2 (#112)
dependabot[bot] Jan 22, 2024
3366c6b
Update dependabot.yml
eriklindgren Jan 22, 2024
1495c89
Bump actions/checkout from 2 to 4 (#123)
dependabot[bot] Jan 22, 2024
15eaa95
Bump actions/setup-node from 2 to 4 (#122)
dependabot[bot] Jan 22, 2024
6898977
Upgrade to node 20
eriklindgren Jan 23, 2024
0a78d74
Run tests on push to dev
eriklindgren Jan 23, 2024
f38e2bf
Bump axios, openai and postmark (#113)
dependabot[bot] Jan 23, 2024
1411633
99 group chat history by monthyear (#111)
leilabb Feb 5, 2024
ae02100
add test db in compose and gh actions
tonioriol Feb 6, 2024
440785f
add test db setup script
tonioriol Feb 6, 2024
15cae89
move cleanDatabase to a helper file
tonioriol Feb 6, 2024
5e5c418
rm unused test
tonioriol Feb 6, 2024
aa7443d
adjustments to make it work
tonioriol Feb 6, 2024
6b05863
remove header param from playwright and add NODE_ENV=test in gh test …
tonioriol Feb 6, 2024
c4785a6
try again
tonioriol Feb 6, 2024
24c5da2
by god
tonioriol Feb 6, 2024
3d5f480
try again
tonioriol Feb 7, 2024
773e4ba
by god
tonioriol Feb 7, 2024
3116194
by god
tonioriol Feb 7, 2024
87583e8
by god
tonioriol Feb 7, 2024
ee77daa
add register flow test
leilabb Feb 8, 2024
a2220f9
add login flow test
leilabb Feb 9, 2024
a1d25b9
create team test
leilabb Mar 1, 2024
58fe146
add chat/team flow tests
leilabb Mar 5, 2024
d46b1aa
Merge branch 'dev' into 131-add-feature-tests
leilabb Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
run: npx prisma migrate deploy

- name: Run tests
run: npm test
run: npm test
14 changes: 3 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import type { PlaywrightTestConfig } from '@playwright/test'

const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 3000,
command: 'npm run build && node server.js',
url: 'http://localhost:3000',
},
use: {
baseURL: 'http://localhost:3000',
},
testDir: 'tests',
testMatch: /(.+\.)?(test|spec)\.[jt]s/,
Expand Down
3 changes: 2 additions & 1 deletion prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { faker } from '@faker-js/faker'
import { PrismaClient, Role } from '@prisma/client'
import bcrypt from 'bcryptjs'
import pkg from 'bcryptjs'
import { encrypt } from '../src/lib/server/utils/crypto'
import { Models } from '../src/lib/types/models'
import { cleanDatabase } from './helpers'

const prisma = new PrismaClient()
const { hashSync } = pkg

async function seed() {
if (process.env.DEPLOYMENT_ENV !== 'staging' && process.env.DEPLOYMENT_ENV !== 'development') {
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/ChatInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

{#if !loading}
<button
name="send"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that necessary for the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. There was no other way I could find that targets the send button otherwise.

on:click={dispatchMessage}
disabled={loading}
class="p-3 pr-14 w-12 rounded-r-xl bg-neutral-500 group"
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ChevronUpIcon,
} from '@babeard/svelte-heroicons/solid'


import { categorizeDate } from '$lib/utils/time'

export let user: UserWithUserTeamsActiveTeamAndChats
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const dateFromLastYear = new Date(
currentDate.getDate()
)
const twoYearsAgo = new Date(currentDate)

twoYearsAgo.setFullYear(currentDate.getFullYear() - 2)

const twoYearsAhead = new Date(currentDate)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const timeSince = (date: Date) => {
}
}


export const categorizeDate = (date: Date): { key: string; label: string; isOpen: boolean } => {
if (isToday(date)) {
return { key: 'today', label: 'Today', isOpen: true }
Expand All @@ -45,6 +46,7 @@ export const categorizeDate = (date: Date): { key: string; label: string; isOpen
millisecondsPerDay < millisecondsSince(date) &&
millisecondsSince(date) <= previousSevenDays
) {

return { key: 'previousSevenDays', label: 'Previous 7 Days', isOpen: true }
} else if (
previousSevenDays < millisecondsSince(date) &&
Expand Down
157 changes: 157 additions & 0 deletions tests/flows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { expect, test } from '@playwright/test'
import { faker } from '@faker-js/faker'
import { cleanDatabase } from '../prisma/helpers'
import { PrismaClient, Role } from '@prisma/client'
import { encrypt } from '../src/lib/server/utils/crypto'
import pkg from 'bcryptjs'

const { hashSync } = pkg
const prisma = new PrismaClient()

type Team = {
id: number
name: string
openAiApiKey: string | null
createdAt: Date
updatedAt: Date
}

async function createTeam(name: string) {
return await prisma.team.create({
data: {
name: name,
openAiApiKey:
process.env.OPENAI_API_KEY && process.env.SECRET_KEY
? encrypt(process.env.OPENAI_API_KEY, process.env.SECRET_KEY)
: null,
},
})
}

async function createUser(team: Team) {
const email = '[email protected]'
return await prisma.user.create({
data: {
email,
name: 'Test1',
password: {
create: {
hash: hashSync('password', 10),
},
},
userTeams: {
create: {
teamId: team.id,
role: Role.OWNER,
},
},
},
include: {
userTeams: true,
},
})
}

test.describe('app flow tests', () => {
test.beforeEach(async () => {
await cleanDatabase()
})

test('register flow', async ({ page }) => {
const name = faker.person.firstName()
const email = faker.internet.email()
const password = faker.internet.password()

await page.goto('/')
await page.getByText('Register').click()
await expect(page).toHaveURL('/signup')

await page.getByLabel('Name').fill(name)
await page.getByLabel('Email').fill(email)
await page.getByLabel('Password', { exact: true }).fill(password)
await page.getByLabel('Confirm Password').fill(password)

await page.getByText('Sign up').click()

await page.waitForURL('/app/settings/teams')

await expect(page).toHaveURL('/app/settings/teams')
}),
test('login flow', async ({ page }) => {
let team = await createTeam('Test Team')
let user = await createUser(team)

await page.goto('/')
await page.getByText('Sign in').click()
await expect(page).toHaveURL('/signin')

await page.getByLabel('Email').fill(user.email)
await page.getByLabel('Password', { exact: true }).fill('password')
await page.getByRole('button').click()

await page.waitForURL('/app/settings/teams')

await expect(page).toHaveURL('/app/settings/teams')
}),
test('create a team', async ({ page }) => {
let team = await createTeam('Test Team')
let user = await createUser(team)

//log in
await page.goto('/')
await page.getByText('Sign in').click()
await expect(page).toHaveURL('/signin')

await page.getByLabel('Email').fill(user.email)
await page.getByLabel('Password', { exact: true }).fill('password')
await page.getByRole('button').click()

await page.waitForURL('/app/settings/teams')

await expect(page).toHaveURL('/app/settings/teams')

//close popup
await page.getByRole('button', { name: /Close/i }).click()

//create new team
await page.getByText('New Team').click()
await expect(page).toHaveURL('/app/settings/teams/new')

await page.getByLabel('Name*').fill('Test Team 2')
await page.getByLabel('OpenAI API Key*').fill(process.env.OPENAI_API_KEY || '')
await page.getByRole('button', { name: /Create/i }).click()

await page.waitForURL(new RegExp('app/settings/teams/\\d+'))
await expect(page).toHaveURL(new RegExp('app/settings/teams/\\d+'))
}),
test('create a chat', async ({ page }) => {
let team = await createTeam('Test Team')
let user = await createUser(team)

//log in
await page.goto('/')
await page.getByText('Sign in').click()
await expect(page).toHaveURL('/signin')

await page.getByLabel('Email').fill(user.email)
await page.getByLabel('Password', { exact: true }).fill('password')
await page.getByRole('button').click()

await page.waitForURL('/app/settings/teams')

await expect(page).toHaveURL('/app/settings/teams')
//select a team
await page.getByRole('button', { name: /Select/i }).click()
await page.waitForURL('/app')
await expect(page).toHaveURL('/app')

//type
await page.getByRole('textbox').fill('Dis a test chat')
//send
await page.locator('button[name="send"]').click()

await page.waitForTimeout(1000)
await page.waitForURL(new RegExp('/app/chats/\\d+'))
await expect(page).toHaveURL(new RegExp('/app/chats/\\d+'))
})
})
Loading