Skip to content

Commit

Permalink
improve README, tidy up replicate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed May 16, 2023
1 parent b62dc61 commit d7288f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
## Usage

```js
var TestBot = require('scuttle-testbot')
const TestBot = require('scuttle-testbot')

var piet = TestBot()
const piet = TestBot()
const content = { type: 'test', text: "a test message" }

piet.publish({type: 'test', content: "a test message"}, (err, msg) => {
piet.db.create publish({ content }, (err, msg) => {
console.log(msg)
piet.close()
})
Expand All @@ -36,7 +37,7 @@ Outputs:
## API

```js
var TestBot = require('scuttle-testbot')
const TestBot = require('scuttle-testbot')
```

### `TestBot(opts = {})`
Expand All @@ -57,6 +58,7 @@ Valid `opts` keys include:
- note `opts.startUnclean` is still accepted
- `opts.db1` (default: `false`)
- uses `ssb-db2` by default, but if `true` will use `ssb-db`
- your can also switch to db1 by setting the ENV `SSB_DB1=true`

### `TestBot.use(plugin)`

Expand All @@ -82,17 +84,25 @@ which are only triggered by _another_ feedId, e.g. when I am added to a private
Example:

```js
const piet = TestBot()
const katie = TestBot()
function Server (opts) {
const stack = require('scuttle-testbot')
// required for replicate
.use(require('ssb-db2/compat/feedstate'))
.use(require('ssb-db2/compat/history-stream'))

return stack(opts)
}
const piet = Server({ name: 'piet' })
const katie = Server({ name: 'katie' })

const content = {
type: 'direct-message',
text: 'oh hey'
}

piet.publish(content, (err, msg) => {
piet.db.create({ content }, (err, msg) => {
TestBot.replicate({ from: piet, to: katie }, (err) => {
katie.get({ id: msg.key, private: true }, (err, value) => {
katie.db.getMsg(msg.key, private: true }, (err, value) => {

console.log(value.content)
// should be same as content piet sent, if katie can decrypt
Expand Down Expand Up @@ -147,16 +157,17 @@ Example:
```js
const crypto = require('crypto')

const Server = (opts) => {
function Server (opts) {
const stack = require('scuttle-testbot')
.use('ssb-conn')
.use('ssb-friends') // only needed if opts.friends

return stack(opts)
}

const caps = { shs: crypto.randomBytes(32).toString('base64') }
const piet = Server({ caps })
const katie = Server({ caps })
const piet = Server({ caps, name: 'piet' })
const katie = Server({ caps, name: 'katie' })
// all peers need to have same caps to be able to connect to each other

Testbot.connect([piet, katie], { friends: true }, (err) => {
Expand Down
7 changes: 0 additions & 7 deletions test/replicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ function TestBot (opts) {
require('ssb-db2/compat/publish'),
// needed for replicate
require('ssb-db2/compat/feedstate'),
require('ssb-db2/compat/ebt'),
require('ssb-db2/compat/log-stream'),
require('ssb-db2/compat/history-stream')
])
}

stack
.use(require('ssb-conn'))
.use(require('ssb-friends'))
.use(require('ssb-replicate')) // required by this version of friends

plugins.forEach(plugin => stack.use(plugin))
plugins = []

Expand Down

0 comments on commit d7288f3

Please sign in to comment.