Skip to content

Commit

Permalink
fix up the tests and the way the map was parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 6, 2023
1 parent 0a7d80b commit ada1c44
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
17 changes: 17 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,23 @@ test('canManagePreferences', async () => {
)
}

const boConsentList = await bo.contacts.consentList()
await delayToPropogate()

if (boConsentList.size !== 1) {
throw new Error(`consent list for bo should 1 not ${boConsentList.size}`)
}

const boConsentListState = boConsentList.get(
`address-${alixConversation.peerAddress.toLowerCase()}`
)

if (boConsentListState !== 'denied') {
throw new Error(
`conversations denied by bo should be denied in consent list not ${boConsentListState}`
)
}

return true
})

Expand Down
17 changes: 5 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,12 @@ export function refreshConsentList(clientAddress: string) {
export async function consentList(
clientAddress: string
): Promise<Map<string, 'allowed' | 'denied' | 'unknown'>> {
return jsonArrayToMap(await XMTPModule.consentList(clientAddress))
}

function jsonArrayToMap(jsonArray: string[]): Map<string, any> {
const result = new Map<string, any>()
const consentList = await XMTPModule.consentList(clientAddress)
const result = new Map<string, 'allowed' | 'denied' | 'unknown'>()

jsonArray.forEach((jsonString) => {
const parsedObject = JSON.parse(jsonString)
if (parsedObject && parsedObject.key) {
result.set(parsedObject.key, parsedObject)
} else {
console.error('Invalid JSON structure:', jsonString)
}
consentList.forEach((item) => {
const [key, value] = item.split(':').map((str: string) => str.trim())
result.set(key.toLowerCase(), value)
})

return result
Expand Down

0 comments on commit ada1c44

Please sign in to comment.