@orieljs/testing 0.1.0-alpha.1 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Application, ModelInstance, Encrypter, Session, View, Authenticatable, Container, AuthFactory, ServiceProvider, ServiceProviderClass, DatabaseManager, Row, ExceptionHandler, ViewFactory, Class, Token, EventDispatcher, Listener, PendingBatchOptions, Job, BusDispatcher, PendingChain, PendingBatch, Batch, QueuePayload, QueueManager, Queue, QueueJob, MailManager, Mailable, Address, MailRecipient, Mailer, PendingMail, SentMessage, MailTransport, Notifiable, NotificationDispatcher, Notification, NotificationChannel, Filesystem, PutOptions, UploadedFile, FilesystemManager } from '@orieljs/contracts';
1
+ import { Application, ModelInstance, InertiaPage, Encrypter, Session, View, Authenticatable, Container, AuthFactory, ServiceProvider, ServiceProviderClass, DatabaseManager, Row, ExceptionHandler, ViewFactory, Class, Token, EventDispatcher, Listener, PendingBatchOptions, Job, BusDispatcher, PendingChain, PendingBatch, Batch, QueuePayload, QueueManager, Queue, QueueJob, MailManager, Mailable, Address, MailRecipient, Mailer, PendingMail, SentMessage, MailTransport, Notifiable, NotificationDispatcher, Notification, NotificationChannel, Filesystem, PutOptions, UploadedFile, FilesystemManager } from '@orieljs/contracts';
2
2
 
3
3
  /**
4
4
  * Laravel's PendingCommand: `await t.artisan('inspire').expectsOutput('…').assertExitCode(0)`.
@@ -43,6 +43,90 @@ type JsonStructure = Array<string | {
43
43
  [key: string]: JsonStructure;
44
44
  };
45
45
 
46
+ type Json = unknown;
47
+ type Scope<T extends AssertableJson> = (json: T) => unknown;
48
+ /**
49
+ * Laravel's Illuminate\Testing\Fluent\AssertableJson: fluent, scoped assertions over decoded JSON. Inside a scope
50
+ * (has(key, callback), first(), each()) every property must be interacted with, or etc() must be called.
51
+ */
52
+ declare class AssertableJson {
53
+ protected readonly props: Json;
54
+ protected readonly path: string | undefined;
55
+ protected interactedKeys: string[];
56
+ constructor(props: Json, path?: string | undefined);
57
+ static fromJson(json: Json): AssertableJson;
58
+ /** A child scope of the same class (subclasses override to keep their extra state out of scopes). */
59
+ protected newScope(props: Json, path: string): AssertableJson;
60
+ protected dotPath(key?: string): string;
61
+ /** The value at `key` in this scope, or the whole scope. */
62
+ protected prop(key?: string): Json;
63
+ /** A literal key of this scope wins over a dot path, like Laravel's Arr::get (keys such as 'items.0.name'). */
64
+ private hasOwnKey;
65
+ private exists;
66
+ protected interactsWith(key: string | number): void;
67
+ /** Every property of the scope was checked (called when a scope ends). */
68
+ interacted(): void;
69
+ /** Allow the properties this scope didn't check. */
70
+ etc(): this;
71
+ /** has('key'), has('key', 3), has('key', json => …), has('key', 3, first => …), or has(3) for the root size. */
72
+ has(key: string | number, length?: number | Scope<this>, callback?: Scope<this>): this;
73
+ /** hasAll(['a', 'b']) or hasAll({ items: 3 }). */
74
+ hasAll(keys: string | string[] | Record<string, number>): this;
75
+ hasAny(keys: string | string[]): this;
76
+ missing(key: string): this;
77
+ missingAll(keys: string | string[]): this;
78
+ /** count(3) checks this scope's size; count('items', 3) a property's. */
79
+ count(key: string | number, length?: number): this;
80
+ countBetween(key: string, min: number, max: number): this;
81
+ /** where('name', 'Ann'), or where('name', value => value.startsWith('A')). Objects compare ignoring key order. */
82
+ where(key: string, expected: unknown): this;
83
+ whereNot(key: string, expected: unknown): this;
84
+ whereNull(key: string): this;
85
+ whereNotNull(key: string): this;
86
+ whereAll(bindings: Record<string, unknown>): this;
87
+ /** whereType('id', 'integer'), whereType('name', 'string|null'), whereType('tags', ['array', 'null']). */
88
+ whereType(key: string, expected: string | string[]): this;
89
+ whereAllType(bindings: Record<string, string | string[]>): this;
90
+ /** The list contains every expected value (or one passing the callback); a string contains the substring. */
91
+ whereContains(key: string, expected: unknown): this;
92
+ protected scope(key: string, callback: Scope<this>): this;
93
+ first(callback: Scope<this>): this;
94
+ each(callback: Scope<this>): this;
95
+ when(condition: unknown, callback: (json: this) => unknown, otherwise?: (json: this) => unknown): this;
96
+ dump(key?: string): this;
97
+ toArray(): Json;
98
+ }
99
+
100
+ /** The page object of a response: the JSON body of an Inertia visit, or the page script of a first visit. */
101
+ declare function inertiaPageOf(response: TestResponse): InertiaPage;
102
+ /** Inertia's AssertableInertia: AssertableJson over the page props, plus the page component, url, version and flash. */
103
+ declare class AssertableInertia extends AssertableJson {
104
+ #private;
105
+ static fromTestResponse(response: TestResponse): AssertableInertia;
106
+ /** Scopes are plain AssertableJson: the page-level methods only make sense at the root. */
107
+ protected newScope(props: unknown, path: string): AssertableJson;
108
+ get page(): InertiaPage;
109
+ /** The component name; the page file must exist unless `shouldExist` is false (inertia.testing.ensure_pages_exist). */
110
+ component(value?: string, shouldExist?: boolean): this;
111
+ url(value: string): this;
112
+ version(value: string): this;
113
+ /** The flash data has `key` (dot paths allowed), equal to `expected` when given. */
114
+ hasFlash(key: string, ...expected: [] | [unknown]): this;
115
+ missingFlash(key: string): this;
116
+ static assertFlashHas(flash: Record<string, unknown>, key: string, ...expected: [] | [unknown]): void;
117
+ static assertFlashMissing(flash: Record<string, unknown>, key: string): void;
118
+ /**
119
+ * Requests the page again as a partial reload (only/except) and checks it is the same page. Uses the test's
120
+ * HTTP client, so the session and cookies carry over.
121
+ */
122
+ reload(callback?: (page: AssertableInertia) => unknown, only?: string | string[], except?: string | string[]): Promise<this>;
123
+ reloadOnly(only: string | string[], callback?: (page: AssertableInertia) => unknown): Promise<this>;
124
+ reloadExcept(except: string | string[], callback?: (page: AssertableInertia) => unknown): Promise<this>;
125
+ /** Loads the deferred props of every group (or the given groups) in one partial reload. */
126
+ loadDeferredProps(groupsOrCallback: string | string[] | ((page: AssertableInertia) => unknown), callback?: (page: AssertableInertia) => unknown): Promise<this>;
127
+ toArray(): Record<string, unknown>;
128
+ }
129
+
46
130
  /** Laravel's CookieValuePrefix: hmac_sha1(name + 'v2', key) + '|' (41 characters), as Auth's EncryptCookies writes it. */
47
131
  declare function cookiePrefix(name: string, key: Uint8Array): string;
48
132
  /** What EncryptCookies puts in a browser cookie: encrypt(prefix + value, serialize: false). */
@@ -83,6 +167,8 @@ interface ResponseContext {
83
167
  views?: View[];
84
168
  /** The last error the exception handler rendered. */
85
169
  exception?: unknown;
170
+ /** The client that sent the request (Inertia reloads reuse it, keeping the session and cookies). */
171
+ client?: HttpClient;
86
172
  }
87
173
  /** Laravel's TestResponse: a Response with its body already read, plus fluent assertions. */
88
174
  declare class TestResponse {
@@ -146,8 +232,24 @@ declare class TestResponse {
146
232
  assertSeeText(value: string | string[], escape?: boolean): this;
147
233
  assertDontSeeText(value: string | string[], escape?: boolean): this;
148
234
  assertSeeTextInOrder(values: string[], escape?: boolean): this;
149
- /** The response JSON contains `data` (a subset match: extra keys in the response are fine). */
150
- assertJson(data: Record<string, unknown> | unknown[]): this;
235
+ /**
236
+ * The response JSON contains `data` (a subset match: extra keys in the response are fine), or fluent
237
+ * assertions: assertJson(json => json.has('data', 3).etc()).
238
+ */
239
+ assertJson(data: Record<string, unknown> | unknown[] | ((json: AssertableJson) => unknown)): this;
240
+ /**
241
+ * An Inertia page response, with optional fluent assertions over its props. An async callback (reload(),
242
+ * loadDeferredProps()) makes this return a promise: await it.
243
+ */
244
+ assertInertia(callback: (page: AssertableInertia) => Promise<unknown>): Promise<this>;
245
+ assertInertia(callback?: (page: AssertableInertia) => unknown): this;
246
+ /** The Inertia page object of this response. */
247
+ inertiaPage(): InertiaPage;
248
+ /** The page props, or one prop by dot path. */
249
+ inertiaProps<T = unknown>(key?: string): T;
250
+ /** Inertia flash data waiting in the session for the next page (after a redirect). */
251
+ assertInertiaFlash(key: string, ...expected: [] | [unknown]): this;
252
+ assertInertiaFlashMissing(key: string): this;
151
253
  /** The response JSON equals `data` exactly (object key order is ignored). */
152
254
  assertExactJson(data: unknown): this;
153
255
  /** The value at `path` equals `expected` (strictly), or passes the predicate. */
@@ -858,4 +960,4 @@ declare const FakeFile: {
858
960
  image(name: string, width?: number, height?: number): File;
859
961
  };
860
962
 
861
- export { AnonymousNotifiable, type BatchRecord, type BootOptions, BusFake, type CountOrFilter, DatabaseMigrations, type DatabaseTestOptions, DatabaseTransactions, type DispatchedEvent, EventFake, type ExpectedErrors, FakeDisk, FakeFile, HttpClient, InteractsWithApplication, InteractsWithConsole, InteractsWithDatabase, type JsonStructure, MailFake, MailRecord, MakesHttpRequests, NotificationFake, PendingCommand, type PushedJob, QueueFake, RefreshDatabase, RefreshDatabaseState, type RequestData, type RequestOptions, type ResponseContext, type ResponseCookie, SHOULD_QUEUE, type SentNotification, StorageFake, TESTING_ENVIRONMENT, type TableOrModel, type Target, TestCase, type TestHooks, TestResponse, type TestTrait, actingAsAuthFactory, addresses, applyEnvironment, cookieHeader, cookiePrefix, decryptCookie, encryptCookie, flatten, guessMimeType, install, isExpired, isQueueable, matches, nameOf, parseSetCookie, recordingExceptionHandler, recordingViewFactory, responseCookies, runCommand, usingInMemoryDatabase };
963
+ export { AnonymousNotifiable, AssertableInertia, AssertableJson, type BatchRecord, type BootOptions, BusFake, type CountOrFilter, DatabaseMigrations, type DatabaseTestOptions, DatabaseTransactions, type DispatchedEvent, EventFake, type ExpectedErrors, FakeDisk, FakeFile, HttpClient, InteractsWithApplication, InteractsWithConsole, InteractsWithDatabase, type JsonStructure, MailFake, MailRecord, MakesHttpRequests, NotificationFake, PendingCommand, type PushedJob, QueueFake, RefreshDatabase, RefreshDatabaseState, type RequestData, type RequestOptions, type ResponseContext, type ResponseCookie, SHOULD_QUEUE, type SentNotification, StorageFake, TESTING_ENVIRONMENT, type TableOrModel, type Target, TestCase, type TestHooks, TestResponse, type TestTrait, actingAsAuthFactory, addresses, applyEnvironment, cookieHeader, cookiePrefix, decryptCookie, encryptCookie, flatten, guessMimeType, inertiaPageOf, install, isExpired, isQueueable, matches, nameOf, parseSetCookie, recordingExceptionHandler, recordingViewFactory, responseCookies, runCommand, usingInMemoryDatabase };