Skip to content

Commit

Permalink
fix(firestore): correctly support delete field (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
prescottprue authored Dec 31, 2022
1 parent a0d943a commit a72cdb2
Show file tree
Hide file tree
Showing 12 changed files with 888 additions and 382 deletions.
11 changes: 11 additions & 0 deletions examples/typescript/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.ts')(on, config)
},
},
})
1 change: 0 additions & 1 deletion examples/typescript/cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { deleteField, Timestamp } from "firebase/firestore";

describe('callFirestore', () => {
describe('get', () => {
before(() => {
Expand Down Expand Up @@ -125,4 +127,23 @@ describe('callFirestore', () => {
});
});
});

it('write nested timestamp field', () => {
const time = Timestamp.fromDate(new Date())
cy.callFirestore('set', 'test/foo', { test: [{ time }] })
cy.callFirestore('get', 'test/foo').then((doc) => {
expect(doc).to.have.nested.property('test.0.time._seconds')
expect(doc).to.have.nested.property('test.0.time._nanoseconds')
})
});

it('update should allow deleting of a field', () => {
const originalDoc = { name: 'toDelete', some: 'asdf' }
cy.callFirestore('set', 'my-collection/doc-id', originalDoc)
cy.callFirestore('update', 'my-collection/doc-id', { some: deleteField() });
cy.callFirestore('get', 'my-collection/doc-id').then((doc) => {
expect(doc).to.not.have.property('some')
expect(doc).to.have.property('name', originalDoc.name)
})
});
});
File renamed without changes.
File renamed without changes.
47 changes: 24 additions & 23 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
"name": "typescript",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.0.0",
"@types/jest": "^28.0.0",
"@types/node": "^16.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"firebase": "^9.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.1",
"typescript": "^4.1.2",
"web-vitals": "^2.0.0"
},
"scripts": {
"start": "react-scripts start",
"start:emulate": "cross-env REACT_APP_USE_DB_EMULATORS=true yarn start",
Expand All @@ -29,6 +14,30 @@
"test:open": "cross-env GCLOUD_PROJECT=redux-firebasev3 CYPRESS_baseUrl=http://localhost:3000 cypress open",
"test:emulate": "cross-env FIREBASE_AUTH_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.auth.port)\" FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.database.port)\" FIRESTORE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.firestore.port)\" yarn test:open"
},
"dependencies": {
"firebase": "^9.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.1",
"typescript": "^4.1.2",
"web-vitals": "^2.0.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.0.0",
"@types/jest": "^28.0.0",
"@types/node": "^16.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"cross-env": "7.0.3",
"cypress": "12.2.0",
"cypress-firebase": "2.2.2",
"eslint-plugin-chai-friendly": "0.7.2",
"eslint-plugin-cypress": "2.12.1",
"firebase-admin": "11.4.1",
"firebase-tools": "11.19.0"
},
"eslintConfig": {
"extends": [
"react-app",
Expand All @@ -46,13 +55,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"cross-env": "7.0.3",
"cypress": "10.11.0",
"cypress-firebase": "2.2.2",
"eslint-plugin-chai-friendly": "0.7.2",
"eslint-plugin-cypress": "2.12.1",
"firebase-tools": "10.9.2"
}
}
4 changes: 2 additions & 2 deletions examples/typescript/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import logo from './logo.svg';
// import logo from './logo.svg';
import initFirebase from './initFirebase'
import RTDBProjects from './RTDBProjects'
import NewProject from './NewProject'
Expand All @@ -12,7 +12,7 @@ function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
{/* <img src={logo} className="App-logo" alt="logo" /> */}
<h2>Data From RTDB</h2>
<RTDBProjects />
<NewProject />
Expand Down
3 changes: 2 additions & 1 deletion examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": ["es5", "dom", "dom.iterable", "esnext"],
"types": ["cypress", "node"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand Down
Loading

0 comments on commit a72cdb2

Please sign in to comment.