Skip to content

Commit

Permalink
message-store: no need to grow examplePutCategory API to track stream…
Browse files Browse the repository at this point in the history
… names
  • Loading branch information
mpareja committed Jul 28, 2020
1 parent a808809 commit 44f8074
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
8 changes: 2 additions & 6 deletions message-store/examples/example-put.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ exports.examplePut = async (messageStore, { category, streamName, count, trackMe
return { streamName, position, messages }
}

exports.examplePutCategory = async (messageStore, { category, count, trackStreamNames = true, trackMessages = true } = {}) => {
exports.examplePutCategory = async (messageStore, { category, count, trackMessages = true } = {}) => {
count = count || 1
category = category || exampleCategory()

const messages = []
const streamNames = []
let position
while (count--) {
const streamName = exampleStreamName(category)
if (trackStreamNames) {
streamNames.push(streamName)
}
const message = exampleWriteMessageData()
if (trackMessages) {
messages.push(message)
}
position = await messageStore.put(message, streamName)
}
return { category, position, streamNames, messages }
return { category, position, messages }
}
11 changes: 5 additions & 6 deletions message-store/postgres/test/message-store-postgres.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('message-store-postgres', () => {
describe('get-stream', () => {
describe('sql condition', () => {
describe('when not provided', () => {
it('parameter defaults to null, returns all results', async () => {
it('returns all results', async () => {
const log = createTestLog()
const messageStore = createMessageStore({ log })
const { streamName } = await examplePut(messageStore, { count: 3 })
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('message-store-postgres', () => {
describe('get-category', () => {
describe('sql condition', () => {
describe('when not provided', () => {
it('parameter defaults to null, returns all results', async () => {
it('returns all results', async () => {
const log = createTestLog()
const messageStore = createMessageStore({ log })
const { category } = await examplePutCategory(messageStore, { count: 3 })
Expand All @@ -97,12 +97,11 @@ describe('message-store-postgres', () => {
it('limits the results based on given sql condition', async () => {
const log = createTestLog()
const messageStore = createMessageStore({ log })
const { category, messages, streamNames } = await examplePutCategory(messageStore, { count: 3, trackStreamNames: true, trackMessages: true })
const { category, messages } = await examplePutCategory(messageStore, { count: 3, trackMessages: true })

const streamName = streamNames[0]
const expectedMessage = messages[0]
const expectedMessage = messages[2]

const CONDITION_SQL = `messages.stream_name = '${streamName}'`
const CONDITION_SQL = `messages.id = '${expectedMessage.id}'`
const results = await messageStore.getCategory(category, { condition: CONDITION_SQL })

expect(results.length).toBe(1)
Expand Down
13 changes: 0 additions & 13 deletions message-store/test/put-test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,13 @@ exports.generatePutSuite = ({

describe('example-put-category', () => {
describe('given no options', () => {
it('tracks the only target streamName', async () => {
const { streamNames } = await examplePutCategory(messageStore)

expect(streamNames).toHaveLength(1)
})

it('tracks the only message written', async () => {
const { messages } = await examplePutCategory(messageStore)

expect(messages).toHaveLength(1)
})
})

describe('when trackStreamNames is false', () => {
it('does not track streamNames', async () => {
const { streamNames } = await examplePutCategory(messageStore, { trackStreamNames: false })
expect(streamNames).toHaveLength(0)
})
})

describe('when trackMessages is false', () => {
it('does not track messages', async () => {
const { messages } = await examplePutCategory(messageStore, { trackMessages: false })
Expand Down

0 comments on commit 44f8074

Please sign in to comment.