Skip to content

Commit

Permalink
Merge pull request #57 from mbc-net/test/core-publish
Browse files Browse the repository at this point in the history
[CLI]: add more test about checking data in command, data, history table and optimistic lock
  • Loading branch information
koichimurakami authored Nov 19, 2024
2 parents 9059382 + af70495 commit cb68665
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/run-test-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Build packages
run: npm run build

- name: Run Unit Tests
run: npm run test

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/run-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Build packages
run: npm run build

- name: Run Unit Tests
run: npm run test

Expand Down
98 changes: 89 additions & 9 deletions packages/core/test/e2e/publish.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { syncDataFinished } from './utils'
const API_PATH = '/api/testing'

describe('Publish', () => {
it('should be stored correct data in DDB', async () => {
it('should be stored correct data in the command DDB table', async () => {
// Arrange
const payload = {
pk: 'TEST',
sk: 'publish',
id: 'TEST#publish',
name: 'testing',
sk: 'publish#command',
id: 'TEST#publish#command',
name: 'testing#command',
version: 0,
code: 'publish',
code: 'publish#command',
type: 'TEST',
}

Expand All @@ -25,16 +25,93 @@ describe('Publish', () => {
// Assert
expect(res.statusCode).toEqual(201)

await syncDataFinished('testing-table', { pk: 'TEST', sk: 'publish@1' })
await syncDataFinished('testing-table', {
pk: payload.pk,
sk: `${payload.sk}@1`,
})

const data = await getItem(getTableName('testing-table', TableType.DATA), {
const data = await getItem(
getTableName('testing-table', TableType.COMMAND),
{
pk: payload.pk,
sk: `${payload.sk}@1`,
},
)

console.log('data', data)

expect(data).toMatchObject({
...payload,
version: 1,
sk: `${payload.sk}@1`,
})
}, 40000)

it('should be stored correct data in the data DDB table', async () => {
// Arrange
const payload = {
pk: 'TEST',
sk: 'publish',
sk: 'publish#data',
id: 'TEST#publish#data',
name: 'testing#data',
version: 0,
code: 'publish#data',
type: 'TEST',
}

// Action
const res = await request(config.apiBaseUrl).post(API_PATH).send(payload)

// Assert
expect(res.statusCode).toEqual(201)

await syncDataFinished('testing-table', {
pk: payload.pk,
sk: `${payload.sk}@1`,
})

const data = await getItem(getTableName('testing-table', TableType.DATA), {
pk: payload.pk,
sk: payload.sk,
})

expect(data).toMatchObject({ ...payload, version: 1 })
}, 40000)

it('should be stored correct data in the history DDB table', async () => {
// Arrange
const payload = {
pk: 'TEST',
sk: 'publish#history',
id: 'TEST#publish#history',
name: 'testing#history',
version: 0,
code: 'publish#history',
type: 'TEST',
}

// Action
const res = await request(config.apiBaseUrl).post(API_PATH).send(payload)

await syncDataFinished('testing-table', {
pk: payload.pk,
sk: `${payload.sk}@1`,
})

// Assert
expect(res.statusCode).toEqual(201)

const data = await getItem(
getTableName('testing-table', TableType.HISTORY),
{
pk: payload.pk,
sk: `${payload.sk}@1`,
},
)

expect(data).toBeUndefined()
}, 40000)

it('should return invalid input version', async () => {
// Arrange
const payload = {
Expand Down Expand Up @@ -71,7 +148,10 @@ describe('Publish', () => {

await request(config.apiBaseUrl).post(API_PATH).send(payload)

await syncDataFinished('testing-table', { pk: 'TEST', sk: 'publish_2@1' })
await syncDataFinished('testing-table', {
pk: payload.pk,
sk: `${payload.sk}@1`,
})

const res = await request(config.apiBaseUrl).post(API_PATH).send(payload)

Expand Down

0 comments on commit cb68665

Please sign in to comment.