{"id":19501150,"url":"https://github.com/gitbookio/expect-firestore","last_synced_at":"2025-04-25T23:30:56.424Z","repository":{"id":73453399,"uuid":"115133564","full_name":"GitbookIO/expect-firestore","owner":"GitbookIO","description":"API client and Jasmine matchers for the Firestore Rules API","archived":false,"fork":false,"pushed_at":"2018-06-21T12:07:21.000Z","size":62,"stargazers_count":22,"open_issues_count":7,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-21T08:46:30.510Z","etag":null,"topics":["firebase","firestore"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GitbookIO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-22T16:45:39.000Z","updated_at":"2021-11-09T04:16:20.000Z","dependencies_parsed_at":"2023-02-28T13:01:47.426Z","dependency_job_id":null,"html_url":"https://github.com/GitbookIO/expect-firestore","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":"0.16666666666666663","last_synced_commit":"6d8c063b708d2cc9d4cfbbb7210e9752784a2dab"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fexpect-firestore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fexpect-firestore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fexpect-firestore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fexpect-firestore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GitbookIO","download_url":"https://codeload.github.com/GitbookIO/expect-firestore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250912660,"owners_count":21506865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","firestore"],"created_at":"2024-11-10T22:11:38.440Z","updated_at":"2025-04-25T23:30:56.419Z","avatar_url":"https://github.com/GitbookIO.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `expect-firestore`\n\n[![Build Status](https://travis-ci.org/GitbookIO/expect-firestore.svg?branch=master)](https://travis-ci.org/GitbookIO/expect-firestore)\n\nNode module to easily unit tests Firestore rules. It abstract the Firestore Rules testing API to easily mock a dataset.\n\n## Install\n\n```\n$ yarn add expect-firestore\n```\n\n## Usage\n\n```js\nimport assert from 'assert';\nimport * as firestore from 'expect-firestore';\n\nconst database = new firestore.Database({\n    // Credentials from firebase console\n    credential: { project_id: '...', ... },\n    // Fake data to test assertions against\n    data: {\n        // See src/__tests__/fixtures/db.json for an example\n        users: [\n            {\n                key: 'userA',\n                fields: {\n                    name: 'John Doe'\n                },\n                collections: {\n                    favorites: [\n                        ...\n                    ]\n                }\n            },\n            ...\n        ]\n    },\n    // Firestore rules\n    rules: ''\n});\n\n// Authorize the client database\nawait database.authorize();\n\n// Test a get\nconst result = await database.canGet({ uid: 'some_user' }, 'users/userA');\nfirestore.assert(result);\n```\n\n## API\n\n#### Global\n\n- `new firestore.Database({ data, credentials, rules })`: Create a database instance to test rules\n\n  ```js\n  const database = new firestore.Database({\n      credentials: require('credential.json')\n  });\n  ```\n- `firestore.assert(test: TestResult)`: Throw a human readable error if test failed, otherwise do nothing\n\n  ```js\n  const result = await database.canGet({}, 'users/userA');\n  firestore.assert(result);\n  ```\n\n#### `firestore.Database`\n\n- `database.authorize(): Promise\u003cvoid\u003e`: Prepare the testing environment, it must be called at least once.\n\nRun `get`, `set`, `update` and `commit` tests using:\n\n- `database.canGet(auth: FirestoreAuth, document: string): Promise\u003cTestResult\u003e`\n- `database.cannotGet(auth: FirestoreAuth, document: string): Promise\u003cTestResult\u003e`\n- `database.canSet(auth: FirestoreAuth, document: string, value: any): Promise\u003cTestResult\u003e`\n- `database.cannotSet(auth: FirestoreAuth, document: string, value: any): Promise\u003cTestResult\u003e`\n- `database.canUpdate(auth: FirestoreAuth, document: string, values: Object): Promise\u003cTestResult\u003e`\n- `database.cannotUpdate(auth: FirestoreAuth, document: string, values: Object): Promise\u003cTestResult\u003e`\n- `database.canCommit(auth: FirestoreAuth, batch: BatchOperation[]): Promise\u003cTestResult\u003e`\n- `database.cannotCommit(auth: FirestoreAuth, batch: firestore.BatchOperation[]): Promise\u003cTestResult\u003e`\n\nControl test testing environment using:\n\n- `database.setData(data: FirestoreCollections)`: Update the dataset\n- `database.setRules(rules: string)`: Update the rules being tested\n- `database.setRulesFromFile(file: string)`: Read the rules from a file\n\n### `firestore.Batch`\n\n- `firestore.Batch.set(document: string, value: any): BatchOperation`\n- `firestore.Batch.update(document: string, values: Object): BatchOperation`\n- `firestore.Batch.delete(document: string): BatchOperation`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitbookio%2Fexpect-firestore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitbookio%2Fexpect-firestore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitbookio%2Fexpect-firestore/lists"}