Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Jun 10, 2023
1 parent baab2c8 commit 70bb1f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 50 deletions.
53 changes: 13 additions & 40 deletions tests/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const redis: RedisClientType = createClient({
import { InMemorySessions } from '../src/stores/inmemory'
import { RedisSessions } from '../src/stores/redis'
import { ISessions } from '../src/types'

import { SessionUtils } from '../src/utils'
import { filter } from './utils'

type SessionId = string
type Meta =
Expand Down Expand Up @@ -116,27 +114,15 @@ for (const { label, sessions, cleanup } of STORES) {
})

test('correctly lists all sessions', async () => {
await store.createSession({ userId: 'user-id', label: '#1', meta: {} })
await store.createSession({ userId: 'user-id', label: '#2', meta: {} })
await store.createSession({ userId: 'user-id', label: '#3', meta: {} })

await expect(
// We filter out random values and dates.
store.listSessions().then((r) => r.map((o) => filter(o, ['label', 'userId']))),
).resolves.toEqual([
{
label: '#3',
userId: 'user-id',
},
{
label: '#2',
userId: 'user-id',
},
{
label: '#1',
userId: 'user-id',
},
])
const userId = 'user-id'
await store.createSession({ userId, label: '#1', meta: {} })
await store.createSession({ userId, label: '#2', meta: {} })
await store.createSession({ userId, label: '#3', meta: {} })

const allSystemSessions = await store.listSessions()

expect(allSystemSessions.every((s) => s.userId === userId)).toBeTruthy()
expect(allSystemSessions.map((s) => s.label)).toEqual(['#3', '#2', '#1'])
})

test('correclty lists sessions for a given user', async () => {
Expand All @@ -150,23 +136,10 @@ for (const { label, sessions, cleanup } of STORES) {
await store.createSession({ userId: otherUserId, label: '#1', meta: {} })
await store.createSession({ userId: otherUserId, label: '#2', meta: {} })

await expect(
// We filter out random values and dates.
store.getSessionsForUser(userId).then((r) => r.map((o) => filter(o, ['label', 'userId']))),
).resolves.toEqual([
{
label: '#3',
userId: 'user-id',
},
{
label: '#2',
userId: 'user-id',
},
{
label: '#1',
userId: 'user-id',
},
])
const allUserIdSessions = await store.getSessionsForUser(userId)

expect(allUserIdSessions.every((s) => s.userId === userId)).toBeTruthy()
expect(allUserIdSessions.map((s) => s.label)).toEqual(['#3', '#2', '#1'])
})
})
}
10 changes: 0 additions & 10 deletions tests/utils.ts

This file was deleted.

0 comments on commit 70bb1f1

Please sign in to comment.