Skip to content

Commit

Permalink
test(datastores): fix broken document operation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Aug 10, 2022
1 parent 43b4bd8 commit c27efd1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Object {
Array [
Object {
"tag": "document.publish",
"visibility": "async",
},
],
],
"create": Array [],
"createIfNotExists": Array [],
"createOrReplace": Array [
Array [
Object {
Expand Down Expand Up @@ -69,6 +71,7 @@ Object {
Array [
Object {
"tag": "document.publish",
"visibility": "async",
},
],
],
Expand All @@ -83,6 +86,7 @@ Object {
},
],
],
"createIfNotExists": Array [],
"createOrReplace": Array [],
"delete": Array [
Array [
Expand Down Expand Up @@ -112,6 +116,7 @@ Object {
Array [
Object {
"tag": "document.publish",
"visibility": "async",
},
],
],
Expand Down Expand Up @@ -152,6 +157,7 @@ Object {
},
],
],
"createIfNotExists": Array [],
"createOrReplace": Array [],
"delete": Array [
Array [
Expand Down
20 changes: 17 additions & 3 deletions packages/sanity/test/mocks/mockSanityClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface MockClientTransactionLog {
id: number
commit: any[][]
create: any[][]
createIfNotExists: any[][]
createOrReplace: any[][]
delete: any[][]
patch: any[][]
Expand Down Expand Up @@ -147,13 +148,20 @@ export function createMockSanityClient(data: {requests?: Record<string, any>} =

return of(requests[opts.uri] || requests['*'] || null)
},

transaction: () => {
// $log.transaction.push(null)
// $log('transaction')

return _createTransaction({observable: true})
},
},

transaction: () => {
// $log.transaction.push(null)
// $log('transaction')

return _createTransaction()
return _createTransaction({observable: false})
},
}

Expand All @@ -162,13 +170,14 @@ export function createMockSanityClient(data: {requests?: Record<string, any>} =

return mockClient

function _createTransaction() {
function _createTransaction({observable}: {observable: boolean}) {
const id = ++transactionId

const $txLog: MockClientTransactionLog = {
id,
commit: [],
create: [],
createIfNotExists: [],
createOrReplace: [],
delete: [],
patch: [],
Expand All @@ -180,13 +189,18 @@ export function createMockSanityClient(data: {requests?: Record<string, any>} =
commit: (...args: any[]) => {
// $log(`transaction#${id}.commit`, ...args)
$txLog.commit.push(args)
return Promise.resolve({})
return observable ? of({}) : Promise.resolve({})
},
create: (...args: any[]) => {
$txLog.create.push(args)
// $log(`transaction#${id}.create`, ...args)
return tx
},
createIfNotExists: (...args: any[]) => {
$txLog.createIfNotExists.push(args)
// $log(`transaction#${id}.createIfNotExists`, ...args)
return tx
},
createOrReplace: (...args: any[]) => {
$txLog.createOrReplace.push(args)
// $log(`transaction#${id}.createOrReplace`, ...args)
Expand Down

0 comments on commit c27efd1

Please sign in to comment.