Skip to content

Commit 7d19427

Browse files
leilabbtoniorioleriklindgrendependabot[bot]
authored
131 add feature tests (#149)
* add key perk to landing page (#107) * add key perk to landing page * fix spelling * 98-clarify-copy-when-creating-a-team * modify copy when creating a new team * add missing env to gh action/workflow --------- Co-authored-by: Toni Oriol <[email protected]> * 104-change-the-word-fork-it-to-clone-including-icon * Change 'fork' to 'clone' and change icon * Change copy of modal after clicking 'Clone' * replace fork with clone * add missing env vars to example * Create dependabot.yml * Bump vite from 4.3.9 to 4.5.2 (#112) Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.3.9 to 4.5.2. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v4.5.2/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v4.5.2/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update dependabot.yml Include GitHub Actions version updates. * Bump actions/checkout from 2 to 4 (#123) Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v2...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/setup-node from 2 to 4 (#122) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2 to 4. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](actions/setup-node@v2...v4) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Upgrade to node 20 * Run tests on push to dev * Bump axios, openai and postmark (#113) * Bump axios, openai and postmark Bumps [axios](https://github.com/axios/axios) to 1.6.5 and updates ancestor dependencies [axios](https://github.com/axios/axios), [openai](https://github.com/openai/openai-node) and [postmark](https://github.com/ActiveCampaign/postmark.js). These dependencies need to be updated together. Updates `axios` from 0.25.0 to 1.6.5 - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](axios/axios@v0.25.0...v1.6.5) Updates `openai` from 3.3.0 to 4.25.0 - [Release notes](https://github.com/openai/openai-node/releases) - [Changelog](https://github.com/openai/openai-node/blob/master/CHANGELOG.md) - [Commits](openai/openai-node@v3.3.0...v4.25.0) Updates `postmark` from 3.0.19 to 4.0.2 - [Release notes](https://github.com/ActiveCampaign/postmark.js/releases) - [Changelog](https://github.com/ActiveCampaign/postmark.js/blob/main/CHANGELOG.md) - [Commits](ActiveCampaign/postmark.js@3.0.19...4.0.2) --- updated-dependencies: - dependency-name: axios dependency-type: indirect - dependency-name: openai dependency-type: direct:production - dependency-name: postmark dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * update to openai@4 fixes --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Toni Oriol <[email protected]> * 99 group chat history by monthyear (#111) * add grouping to chats * add last 30 days group * add last year group * refactor time functions * change function name * change func name * add tests + new grouping function * refactoring * add grouping to all chats ever made * add code fix * change function name * change type name * refactor * style code * add tests * catch future dates¨ * add final fixes * add test db in compose and gh actions * add test db setup script * move cleanDatabase to a helper file * rm unused test * adjustments to make it work * remove header param from playwright and add NODE_ENV=test in gh test action Also adjust DATABASE_URL in env example * try again * by god * try again * by god * by god * by god * add register flow test * add login flow test * create team test * add chat/team flow tests --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Toni Oriol <[email protected]> Co-authored-by: Erik Lindgren <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent f2c2972 commit 7d19427

File tree

9 files changed

+173
-15
lines changed

9 files changed

+173
-15
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ jobs:
5656
run: npx prisma migrate deploy
5757

5858
- name: Run tests
59-
run: npm test
59+
run: npm test

package-lock.json

Lines changed: 3 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playwright.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import type { PlaywrightTestConfig } from '@playwright/test'
22

33
const config: PlaywrightTestConfig = {
44
webServer: {
5-
command: 'npm run build && npm run preview',
6-
port: 3000,
5+
command: 'npm run build && node server.js',
6+
url: 'http://localhost:3000',
7+
},
8+
use: {
9+
baseURL: 'http://localhost:3000',
710
},
811
testDir: 'tests',
912
testMatch: /(.+\.)?(test|spec)\.[jt]s/,

prisma/seed.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { faker } from '@faker-js/faker'
22
import { PrismaClient, Role } from '@prisma/client'
3-
import bcrypt from 'bcryptjs'
3+
import pkg from 'bcryptjs'
44
import { encrypt } from '../src/lib/server/utils/crypto'
55
import { Models } from '../src/lib/types/models'
66
import { cleanDatabase } from './helpers'
77

88
const prisma = new PrismaClient()
9+
const { hashSync } = pkg
910

1011
async function seed() {
1112
if (process.env.DEPLOYMENT_ENV !== 'staging' && process.env.DEPLOYMENT_ENV !== 'development') {

src/lib/components/ChatInput.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
{#if !loading}
9191
<button
92+
name="send"
9293
on:click={dispatchMessage}
9394
disabled={loading}
9495
class="p-3 pr-14 w-12 rounded-r-xl bg-neutral-500 group"

src/lib/components/Sidebar.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ChevronUpIcon,
1111
} from '@babeard/svelte-heroicons/solid'
1212
13+
1314
import { categorizeDate } from '$lib/utils/time'
1415
1516
export let user: UserWithUserTeamsActiveTeamAndChats

src/lib/utils/time.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const dateFromLastYear = new Date(
88
currentDate.getDate()
99
)
1010
const twoYearsAgo = new Date(currentDate)
11+
1112
twoYearsAgo.setFullYear(currentDate.getFullYear() - 2)
1213

1314
const twoYearsAhead = new Date(currentDate)

src/lib/utils/time.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const timeSince = (date: Date) => {
3636
}
3737
}
3838

39+
3940
export const categorizeDate = (date: Date): { key: string; label: string; isOpen: boolean } => {
4041
if (isToday(date)) {
4142
return { key: 'today', label: 'Today', isOpen: true }
@@ -45,6 +46,7 @@ export const categorizeDate = (date: Date): { key: string; label: string; isOpen
4546
millisecondsPerDay < millisecondsSince(date) &&
4647
millisecondsSince(date) <= previousSevenDays
4748
) {
49+
4850
return { key: 'previousSevenDays', label: 'Previous 7 Days', isOpen: true }
4951
} else if (
5052
previousSevenDays < millisecondsSince(date) &&

tests/flows.test.ts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import { expect, test } from '@playwright/test'
2+
import { faker } from '@faker-js/faker'
3+
import { cleanDatabase } from '../prisma/helpers'
4+
import { PrismaClient, Role } from '@prisma/client'
5+
import { encrypt } from '../src/lib/server/utils/crypto'
6+
import pkg from 'bcryptjs'
7+
8+
const { hashSync } = pkg
9+
const prisma = new PrismaClient()
10+
11+
type Team = {
12+
id: number
13+
name: string
14+
openAiApiKey: string | null
15+
createdAt: Date
16+
updatedAt: Date
17+
}
18+
19+
async function createTeam(name: string) {
20+
return await prisma.team.create({
21+
data: {
22+
name: name,
23+
openAiApiKey:
24+
process.env.OPENAI_API_KEY && process.env.SECRET_KEY
25+
? encrypt(process.env.OPENAI_API_KEY, process.env.SECRET_KEY)
26+
: null,
27+
},
28+
})
29+
}
30+
31+
async function createUser(team: Team) {
32+
const email = '[email protected]'
33+
return await prisma.user.create({
34+
data: {
35+
email,
36+
name: 'Test1',
37+
password: {
38+
create: {
39+
hash: hashSync('password', 10),
40+
},
41+
},
42+
userTeams: {
43+
create: {
44+
teamId: team.id,
45+
role: Role.OWNER,
46+
},
47+
},
48+
},
49+
include: {
50+
userTeams: true,
51+
},
52+
})
53+
}
54+
55+
test.describe('app flow tests', () => {
56+
test.beforeEach(async () => {
57+
await cleanDatabase()
58+
})
59+
60+
test('register flow', async ({ page }) => {
61+
const name = faker.person.firstName()
62+
const email = faker.internet.email()
63+
const password = faker.internet.password()
64+
65+
await page.goto('/')
66+
await page.getByText('Register').click()
67+
await expect(page).toHaveURL('/signup')
68+
69+
await page.getByLabel('Name').fill(name)
70+
await page.getByLabel('Email').fill(email)
71+
await page.getByLabel('Password', { exact: true }).fill(password)
72+
await page.getByLabel('Confirm Password').fill(password)
73+
74+
await page.getByText('Sign up').click()
75+
76+
await page.waitForURL('/app/settings/teams')
77+
78+
await expect(page).toHaveURL('/app/settings/teams')
79+
}),
80+
test('login flow', async ({ page }) => {
81+
let team = await createTeam('Test Team')
82+
let user = await createUser(team)
83+
84+
await page.goto('/')
85+
await page.getByText('Sign in').click()
86+
await expect(page).toHaveURL('/signin')
87+
88+
await page.getByLabel('Email').fill(user.email)
89+
await page.getByLabel('Password', { exact: true }).fill('password')
90+
await page.getByRole('button').click()
91+
92+
await page.waitForURL('/app/settings/teams')
93+
94+
await expect(page).toHaveURL('/app/settings/teams')
95+
}),
96+
test('create a team', async ({ page }) => {
97+
let team = await createTeam('Test Team')
98+
let user = await createUser(team)
99+
100+
//log in
101+
await page.goto('/')
102+
await page.getByText('Sign in').click()
103+
await expect(page).toHaveURL('/signin')
104+
105+
await page.getByLabel('Email').fill(user.email)
106+
await page.getByLabel('Password', { exact: true }).fill('password')
107+
await page.getByRole('button').click()
108+
109+
await page.waitForURL('/app/settings/teams')
110+
111+
await expect(page).toHaveURL('/app/settings/teams')
112+
113+
//close popup
114+
await page.getByRole('button', { name: /Close/i }).click()
115+
116+
//create new team
117+
await page.getByText('New Team').click()
118+
await expect(page).toHaveURL('/app/settings/teams/new')
119+
120+
await page.getByLabel('Name*').fill('Test Team 2')
121+
await page.getByLabel('OpenAI API Key*').fill(process.env.OPENAI_API_KEY || '')
122+
await page.getByRole('button', { name: /Create/i }).click()
123+
124+
await page.waitForURL(new RegExp('app/settings/teams/\\d+'))
125+
await expect(page).toHaveURL(new RegExp('app/settings/teams/\\d+'))
126+
}),
127+
test('create a chat', async ({ page }) => {
128+
let team = await createTeam('Test Team')
129+
let user = await createUser(team)
130+
131+
//log in
132+
await page.goto('/')
133+
await page.getByText('Sign in').click()
134+
await expect(page).toHaveURL('/signin')
135+
136+
await page.getByLabel('Email').fill(user.email)
137+
await page.getByLabel('Password', { exact: true }).fill('password')
138+
await page.getByRole('button').click()
139+
140+
await page.waitForURL('/app/settings/teams')
141+
142+
await expect(page).toHaveURL('/app/settings/teams')
143+
//select a team
144+
await page.getByRole('button', { name: /Select/i }).click()
145+
await page.waitForURL('/app')
146+
await expect(page).toHaveURL('/app')
147+
148+
//type
149+
await page.getByRole('textbox').fill('Dis a test chat')
150+
//send
151+
await page.locator('button[name="send"]').click()
152+
153+
await page.waitForTimeout(1000)
154+
await page.waitForURL(new RegExp('/app/chats/\\d+'))
155+
await expect(page).toHaveURL(new RegExp('/app/chats/\\d+'))
156+
})
157+
})

0 commit comments

Comments
 (0)