mattrguerra/meridian-ops-boardmainPrivate on GitHub, published here in full

teams.test.ts

Language TypeScript2.1 KB55 lines

packages/ninety-client/test/teams.test.ts

  1. import { describe, expect, it } from 'vitest'
  2. import { HttpClient } from '../src/http.js'
  3. import { TeamsResource } from '../src/resources/teams.js'
  4. import { RawTeamSchema, normalizeTeam } from '../src/types.js'
  5. import fixture from './fixtures/teams.json' with { type: 'json' }
  6. const http = (body: unknown) =>
  7. new HttpClient({
  8. token: 't',
  9. sleep: async () => {},
  10. rps: 1000,
  11. fetchImpl: (async () =>
  12. new Response(JSON.stringify(body), {
  13. status: 200,
  14. headers: { 'Content-Type': 'application/json' },
  15. })) as unknown as typeof fetch,
  16. })
  17. describe('teams: live shape 2026-08-09', () => {
  18. it('parses the real payload', () => {
  19. const teams = fixture.map((t) => normalizeTeam(RawTeamSchema.parse(t)))
  20. expect(teams.map((t) => t.name)).toEqual(['Leadership Team', 'Operations Team', 'All Hands'])
  21. expect(teams[0]!.companyId).toBe('c776006b89693d432922f3ea')
  22. })
  23. it('confirms Ninety does NOT return team membership', () => {
  24. // This is the assertion that justifies the harvest path in roster.ts.
  25. // If it ever fails, Ninety added membership and roster.ts can get simpler.
  26. for (const raw of fixture) {
  27. expect(raw).not.toHaveProperty('users')
  28. expect(raw).not.toHaveProperty('members')
  29. expect(raw).not.toHaveProperty('userIds')
  30. }
  31. })
  32. it('excludes projects and deleted teams by default', async () => {
  33. const body = [
  34. ...fixture,
  35. { _id: 'p1', name: 'Some Project', project: true, deleted: false },
  36. { _id: 'd1', name: 'Old Team', project: false, deleted: true },
  37. ]
  38. const teams = await new TeamsResource(http(body)).list()
  39. expect(teams.map((t) => t.name)).toEqual(['Leadership Team', 'Operations Team', 'All Hands'])
  40. })
  41. it('includes them when asked', async () => {
  42. const body = [...fixture, { _id: 'p1', name: 'Some Project', project: true, deleted: false }]
  43. const teams = await new TeamsResource(http(body)).list({ includeProjects: true })
  44. expect(teams).toHaveLength(4)
  45. })
  46. it('throws a useful message if the shape changes', async () => {
  47. await expect(new TeamsResource(http({ items: [] })).list()).rejects.toThrow(/did not return an array/)
  48. })
  49. })