-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add table.delete and dynamorm.deleteTables method
- Loading branch information
1 parent
c08a6f7
commit acfe9d3
Showing
12 changed files
with
187 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {DynamormException} from '../src/exceptions'; | ||
import {TestTable, db, client} from './fixtures/test-table'; | ||
|
||
jest.useFakeTimers() | ||
|
||
describe('Create / Delete Table', () => { | ||
|
||
describe('Dynamorm container instance', () => { | ||
it('should create tables from container', async () => { | ||
await expect(db.createTables).rejects.not.toThrow(DynamormException); | ||
}) | ||
|
||
it('should delete tables from container', async () => { | ||
await expect(db.deleteTables).rejects.not.toThrow(DynamormException); | ||
}) | ||
}) | ||
|
||
describe('Table instance', () => { | ||
let table; | ||
|
||
beforeEach(() => { | ||
table = new TestTable(client); | ||
}) | ||
|
||
it('should create database table', async () => { | ||
const createTable = async () => { | ||
setTimeout(async () => await table.create(), 200) | ||
} | ||
expect(createTable).not.toThrow(); | ||
}) | ||
|
||
it('should create database table if not exists', async () => { | ||
const createTable = async () => { | ||
setTimeout(async () => await table.create('IF_NOT_EXISTS'), 200) | ||
} | ||
expect(createTable).not.toThrow(DynamormException); | ||
}) | ||
|
||
it('should delete table', async () => { | ||
const deleteTable = async () => { | ||
setTimeout(async () => await table.delete(), 200) | ||
} | ||
expect(deleteTable).not.toThrow(DynamormException); | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,13 +97,6 @@ describe('app', () => { | |
|
||
}) | ||
|
||
describe('table creation', () => { | ||
it('should create all tables', async () => { | ||
const result = await db.createTables(); | ||
expect(result).toBeInstanceOf(Array); | ||
}) | ||
}) | ||
|
||
describe('save item', () => { | ||
it('should save item', () => { | ||
const model = db.model('AuthorEntity'); | ||
|
@@ -125,7 +118,7 @@ describe('app', () => { | |
const expectedAttributes = { | ||
title: 'Southern Sweets', | ||
author: '[email protected]', | ||
image: [ 'http://images.com/logo.png' ] | ||
image: [ 'logo.png' ] | ||
} | ||
expect(model).toBeInstanceOf(Model); | ||
expect(attributes).toMatchObject(expectedAttributes) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {DynamoDBClient} from '@aws-sdk/client-dynamodb'; | ||
import {attribute, dynamorm, DynamormFactory, Entity, table as TableDecorator, Table} from '../../index'; | ||
|
||
export const client = new DynamoDBClient({endpoint: 'http://localhost:8000'}); | ||
|
||
export class TestEntity extends Entity { | ||
@attribute() | ||
pk: string; | ||
@attribute() | ||
sk: string; | ||
} | ||
|
||
@TableDecorator({ | ||
name: 'TestTable', | ||
primaryKey: {pk: 'pk', sk: 'sk'}, | ||
entity: TestEntity | ||
}) | ||
export class TestTable extends Table {} | ||
|
||
@dynamorm({ | ||
tables: [TestTable], | ||
client | ||
}) | ||
class DB {} | ||
|
||
export const db = DynamormFactory.create(DB); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import db from './fixtures/db' | ||
|
||
export default async function() { | ||
await db.createTables('DROP_IF_EXISTS'); | ||
const model = db.model('Cookbooks') | ||
|
||
await model.fill({ | ||
title: "Southern Savories", | ||
description: 'Southern Cookbook', | ||
author: '[email protected]', | ||
image: ['logo.png'] | ||
}).save(); | ||
await model.set('title', 'Southern Smothered').save(); | ||
await model.set('title', 'Southern Fried').save(); | ||
await model.set('title', 'Southern Sweets').save(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import Model from "../src/model"; | |
|
||
const config = {endpoint: 'http://localhost:8000'}; | ||
const client = new DynamoDBClient(config); | ||
|
||
describe('model', () => { | ||
let model: any; | ||
|
||
|
@@ -140,7 +141,7 @@ describe('model', () => { | |
it('should save', async () => { | ||
model.fill({ | ||
title: "Southern Savories", | ||
author: 'com.joshua360@gmail.com', | ||
author: 'dev@studiowebfx.com', | ||
image: ['logo.png'] | ||
}); | ||
const result = await model.save(); | ||
|
@@ -150,32 +151,32 @@ describe('model', () => { | |
|
||
describe('find', () => { | ||
it('should get item by primary key', async () => { | ||
const result = await model.find('Southern Savories','com.joshua360@gmail.com'); | ||
const result = await model.find('Southern Savories','dev@studiowebfx.com'); | ||
expect(result).toBeInstanceOf(Model) | ||
expect(result.title).toEqual('Southern Savories') | ||
expect(result.author).toEqual('com.joshua360@gmail.com') | ||
expect(result.author).toEqual('dev@studiowebfx.com') | ||
}) | ||
}) | ||
|
||
describe('delete', () => { | ||
it('should delete item by primary key', async () => { | ||
await model.fill({ | ||
title: 'Southern Savories', | ||
author: 'com.joshua360@gmail.com', | ||
author: 'dev@studiowebfx.com', | ||
image: ['image.png'] | ||
}).save(); | ||
const result = await model.delete('Southern Savories','com.joshua360@gmail.com'); | ||
const result = await model.delete('Southern Savories','dev@studiowebfx.com'); | ||
expect(result).toBe(true); | ||
}) | ||
}) | ||
|
||
describe('update', () => { | ||
it('should update item', async () => { | ||
model.fill({ | ||
title: 'Southern Smothered', | ||
title: 'Southern Crunch', | ||
author: '[email protected]', | ||
description: 'Another Cookbook', | ||
image: ["http://images.com/logo.png", "http://images.com/logo2.png"] | ||
image: ["logo.png", "logo2.png"] | ||
}) | ||
const updateModel = async () => await model.update(); | ||
expect(updateModel).not.toThrow() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.