OAuth grants in tests
An OAuth grant lets the app call another service on a user's or a
team's behalf (OAuth grants).
A test declares its grants at the top, beside fakes:, as
grants: { calendar: [platform_team] }: the connection's name, and the
fixtures whose records own a grant. Each time the test calls one of those
fixtures, the record it gives, or the record a caller or an id it gives
names, gets a fake grant, as jadpo dev grants add makes one in
development. A call on behalf of an owner with no grant fails
grant_missing, and a script can answer grant_revoked, which ends the
grant and publishes GrantRevoked as a provider's refusal does.
Here the platform team's stand-up is booked through its grant, the team asked to connect again once its grant is revoked, and a team that never connected is told to:
use app { calendar }use teams/entities { ReconnectRequest }use teams/failures { CalendarNotConnected }use teams/queries { reconnect_requests }use teams/fixtures { platform_team }use shared/providers/google_calendartest "each morning the platform team's stand-up is booked through its grant" { grants: { calendar: [platform_team] } platform_team() attempt standups.run() var sent: List<GoogleCalendar.NewEvent> = calendar.events.insert.requests assert list.map(sent, event -> event.summary) == ["Stand-up"]}test "a grant the provider no longer honours is ended and the team asked again" { grants: { calendar: [platform_team] } fakes: { calendar.events.insert: [grant_revoked] } platform_team() assert standups.run() fails CalendarNotConnected var asked: List<ReconnectRequest> = reconnect_requests() assert list.map(asked, request -> request.reconnect_to) == ["calendar"]}
use app { calendar }use teams/entities { Team }use teams/failures { CalendarNotConnected }use teams/fixtures { platform_team }test "a connected team's stand-up goes into its calendar" { grants: { calendar: [platform_team] } var team: Team = platform_team() attempt add_standup(team.id) assert list.count(calendar.events.insert.requests) == 1}test "a team that hasn't connected is told to" { var team: Team = platform_team() assert add_standup(team.id) fails CalendarNotConnected}
Markdown for agents: /docs/oauth-grants-in-tests.md.Built from Jadpo's main branch at commit f05ed31.