teams.test.ts
Language TypeScript2.1 KB55 lines
import { describe, expect, it } from 'vitest'import { HttpClient } from '../src/http.js'import { TeamsResource } from '../src/resources/teams.js'import { RawTeamSchema, normalizeTeam } from '../src/types.js'import fixture from './fixtures/teams.json' with { type: 'json' }const http = (body: unknown) =>new HttpClient({token: 't',sleep: async () => {},rps: 1000,fetchImpl: (async () =>new Response(JSON.stringify(body), {status: 200,headers: { 'Content-Type': 'application/json' },})) as unknown as typeof fetch,})describe('teams: live shape 2026-08-09', () => {it('parses the real payload', () => {const teams = fixture.map((t) => normalizeTeam(RawTeamSchema.parse(t)))expect(teams.map((t) => t.name)).toEqual(['Leadership Team', 'Operations Team', 'All Hands'])expect(teams[0]!.companyId).toBe('c776006b89693d432922f3ea')})it('confirms Ninety does NOT return team membership', () => {// This is the assertion that justifies the harvest path in roster.ts.// If it ever fails, Ninety added membership and roster.ts can get simpler.for (const raw of fixture) {expect(raw).not.toHaveProperty('users')expect(raw).not.toHaveProperty('members')expect(raw).not.toHaveProperty('userIds')}})it('excludes projects and deleted teams by default', async () => {const body = [...fixture,{ _id: 'p1', name: 'Some Project', project: true, deleted: false },{ _id: 'd1', name: 'Old Team', project: false, deleted: true },]const teams = await new TeamsResource(http(body)).list()expect(teams.map((t) => t.name)).toEqual(['Leadership Team', 'Operations Team', 'All Hands'])})it('includes them when asked', async () => {const body = [...fixture, { _id: 'p1', name: 'Some Project', project: true, deleted: false }]const teams = await new TeamsResource(http(body)).list({ includeProjects: true })expect(teams).toHaveLength(4)})it('throws a useful message if the shape changes', async () => {await expect(new TeamsResource(http({ items: [] })).list()).rejects.toThrow(/did not return an array/)})})