Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
fix: added basic testing for storables
Browse files Browse the repository at this point in the history
  • Loading branch information
villetakanen committed Dec 14, 2021
1 parent a58c7d8 commit 48a8214
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/state/store/Storable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Storable implements StorableModel {
}

compareFlowTime (other:StorableModel): number {
if (other.id !== this.id) return 0 // They are the same entity, return 0
if (other.id === this.id) return 0 // They are the same entity, return 0
if (other.flowTime > this.flowTime) {
return -1
}
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/Storable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Storable } from "@/state/store/Storable"
import { Timestamp } from '@firebase/firestore'

describe('Storable', () => {
it('Should always have an id', () => {
const storable = new Storable('id')
expect(storable.id).toBeDefined();
})
it('Should be comparable to another Storable with a flowTime', () => {
const storable1 = new Storable('id1')
const storable2 = new Storable('id2')
storable1.docData = { updated: new Timestamp(1, 1) }
storable2.docData = { updated: new Timestamp(2, 2) }
expect(storable1.compareFlowTime(storable2)).toBe(-1)
})
})

0 comments on commit 48a8214

Please sign in to comment.