> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Sign-in, review and tracking fakes

Sign in with Apple, count rating requests, or answer the tracking prompt in a unit test. `import { setAppleSignInResult, reviewRequests, setTrackingStatus } from '@blotch/angular-lynx-testing-library';`

## Sign in with Apple

Fakes [`LynxAppleSignIn`](/api/angular-lynx/accounts/apple-sign-in.md)'s native module.

- **Each test starts** with the sheet there, no sign-ins and no users.
- **Until a spec answers**, the person closes the sheet, and `signIn()` rejects with `canceled`.
- **The answer reaches the app through the [background thread](/guide/glossary.md#background-thread)**, as on a phone. Wait for it with `waitForUpdate()`.

```typescript
setAppleSignInResult({ user: 'u1', email: 'ada@example.com' });
await render(SignIn);

fireEvent.tap(screen.getByText('Sign in with Apple'));
await waitForUpdate();

expect(screen.getByText('Signed in as ada@example.com')).toBeInTheDocument();
expect(appleSignInRequests()).toEqual([{ scopes: ['email', 'fullName'] }]);
```

### `setAppleSignInResult()`

```typescript
function setAppleSignInResult(result?: FakeAppleSignInResult): void;
```

Has the person sign in from now on in this test: `signIn()` resolves with `result`.

- **`email` and `fullName`** are shared only when the sign-in asks for their scopes, as Apple does.
- **What's left out takes a test value.** `user` is `test-apple-user`, and the tokens are `test-identity-token` and `test-authorization-code`.
- **Each user it signs in** is `authorized` afterwards.

### `setAppleSignInError()`

```typescript
function setAppleSignInError(
  code: 'canceled' | 'failed',
  message?: string,
): void;
```

Has the next sign-ins reject with `code`.

### `setAppleSignInAvailable()`

```typescript
function setAppleSignInAvailable(available: boolean): void;
```

`false` takes the native sheet away, as on Android and the web.

- **`isAvailable()`** resolves `false`, and `signIn()` rejects with `unsupported`.
- **An [`<apple-sign-in-button>`](/api/elements/apple-sign-in-button.md) made after it** is the one the runtime draws, rather than iOS's element. `getByText()` finds its title.

### `setAppleCredentialState()`

```typescript
function setAppleCredentialState(
  user: string,
  state: 'authorized' | 'revoked' | 'notFound' | 'transferred',
): void;
```

Sets what `getCredentialState(user)` resolves with. A user nobody signed in is `notFound`.

### `appleSignInRequests()`

```typescript
function appleSignInRequests(): readonly AppleSignInRequest[];
```

Lists the sign-ins the app opened, with the `scopes`, `nonce` and `state` each asked for.

## Store review

Counts the rating requests [`LynxStoreReview`](/api/angular-lynx/accounts/store-review.md) makes.

### `reviewRequests()`

```typescript
function reviewRequests(): number;
```

How many times the app asked for a rating with `LynxStoreReview.request()` in this test. A spec can check it asks at the right moment, and only then.

```typescript
fireEvent.tap(screen.getByText('Place order'));
await waitForUpdate();

expect(reviewRequests()).toBe(1);
```

- **`request()` resolves without showing anything.**
- **Each test starts at 0.**

## Tracking

Fakes whether the app may track the person, for [`LynxTracking`](/api/angular-lynx/accounts/tracking.md). Each test starts at `notDetermined`.

### `setTrackingStatus()`

```typescript
function setTrackingStatus(status: FakeTrackingStatus): void;
```

Sets whether the app may track the person, as if they'd answered the prompt or changed it in Settings. It's what `status()` reads, and what `requestPermission()` resolves with.

`FakeTrackingStatus` takes the same values as `TrackingStatus`.

`LynxTracking` reads the status when it's created, and again when the app comes back to the foreground. So set it before `render()`:

```typescript
setTrackingStatus('denied');
await render(Feed);

expect(screen.getByText('Ads that respect your choice')).toBeInTheDocument();
```

Or, after `render()`, follow it with [`setAppState('background')` and `setAppState('active')`](/api/testing-library/fakes/device.md#setappstate), as a person coming back from Settings would. Await `waitForUpdate()` after each. Without the wait between them, the app never seems to leave, and the status isn't read again:

```typescript
setTrackingStatus('denied');
setAppState('background');
await waitForUpdate();
setAppState('active');
await waitForUpdate();

expect(screen.getByText('Ads that respect your choice')).toBeInTheDocument();
```

### `setTrackingAnswer()`

```typescript
function setTrackingAnswer(answer: 'authorized' | 'denied'): void;
```

What the person answers when `requestPermission()` shows the prompt: `authorized` by default. The prompt shows only while the status is `notDetermined`.

### `trackingPrompts()`

```typescript
function trackingPrompts(): number;
```

How many times `requestPermission()` showed the prompt in this test. A spec can check the app asks at the right moment, and only once. Each test starts at 0.

```typescript
setTrackingAnswer('denied');
fireEvent.tap(screen.getByText('Continue'));
await waitForUpdate();

expect(trackingPrompts()).toBe(1);
```

## Types

| Type                       | Description                                                                                       |
| -------------------------- | ------------------------------------------------------------------------------------------------- |
| `FakeAppleSignInResult`    | What `setAppleSignInResult()` takes: `user`, the tokens, `email`, `fullName` and `realUserStatus` |
| `FakeAppleCredentialState` | What `setAppleCredentialState()` takes                                                            |
| `AppleSignInRequest`       | One of `appleSignInRequests()`: `scopes`, `nonce` and `state`                                     |
| `FakeTrackingStatus`       | What `setTrackingStatus()` takes, the same values as `TrackingStatus`                             |

## Related

- [Device fakes](/api/testing-library/fakes/index.md)
- [`LynxAppleSignIn`](/api/angular-lynx/accounts/apple-sign-in.md)
- [`LynxStoreReview`](/api/angular-lynx/accounts/store-review.md)
- [`LynxTracking`](/api/angular-lynx/accounts/tracking.md)
