Skip to content

Commit

Permalink
chore: cleanup unused code (jeremydaly#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
naorpeled committed Apr 8, 2023
1 parent c1cd6eb commit 82391ea
Show file tree
Hide file tree
Showing 26 changed files with 301 additions and 1,222 deletions.
880 changes: 0 additions & 880 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@aws-sdk/lib-dynamodb": "^3.287.0",
"@aws-sdk/client-dynamodb": "^3.287.0",
"coveralls": "^3.1.0",
"dynalite": "^3.2.1",
"eslint": "^8.2.0",
"jest": "^29.2.2",
"prettier": "^2.2.1",
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/entity-creation.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ describe('Entity creation', () => {
DocumentClient
})

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const TestEntity = new Entity({
name: 'TestEnt',
attributes: {
Expand All @@ -402,7 +403,7 @@ describe('Entity creation', () => {
default: 'pkDef'
},
test: {
format: (val: string, data: any) => {
format: (val: string) => {
return val.toUpperCase()
},
default: () => 'defaultVal'
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.parse.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DocumentClient, DocumentClientWithWrappedNumbers } from './bootstrap.test'
import { DocumentClientWithWrappedNumbers } from './bootstrap.test'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
Expand Down Expand Up @@ -257,4 +257,4 @@ describe('parse', () => {
]
})
})
}) // end parse
})
134 changes: 78 additions & 56 deletions src/__tests__/entity.update.unit.test.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/__tests__/misc-tests.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,9 @@ describe('Misc Tests (development only)', () => {
// ProjectionExpression = projections
// _EntityProjections = entities
// _TableProjections = tableAttrs
// } // end if names
// }

// } // end if projections
// }

// // Error if extra arguments are provided along with keys
// if (keys !== undefined && Object.keys(args).length > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/parse.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ describe('parse', () => {
// test_composite3: 'foo'
// })
// })
}) // end parse
})
5 changes: 2 additions & 3 deletions src/__tests__/projectionBuilder.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import projectionBuilder from '../lib/projectionBuilder'

// Require Table and Entity classes
import Table from '../classes/Table'
import Entity from '../classes/Entity'

// Create basic table
const DefaultTable = new Table({
name: 'test-table',
partitionKey: 'pk',
sortKey: 'sk'
})

// Create basic entity
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const User = new Entity({
name: 'User',
attributes: {
Expand All @@ -26,6 +24,7 @@ const User = new Entity({
table: DefaultTable
} as const)

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const Pet = new Entity({
name: 'Pet',
attributes: {
Expand Down
71 changes: 0 additions & 71 deletions src/__tests__/put.int.test.ts

This file was deleted.

192 changes: 100 additions & 92 deletions src/__tests__/table-creation.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ describe('Table creation', () => {
partitionKey: 'pk'
})

expect(TestTable instanceof Table).toBe(true)
expect(TestTable.name).toBe('test-table')
expect(TestTable.Table.partitionKey).toBe('pk')
expect(TestTable.Table.sortKey).toBeNull()
expect(TestTable.Table.entityField).toBe('_et')
expect(TestTable.Table.indexes).toEqual({})
expect(TestTable.Table.attributes).toEqual({ _et: { type: 'string', mappings: {} } })
expect(TestTable.autoExecute).toBe(true)
expect(TestTable.autoParse).toBe(true)
expect(TestTable.entities).toEqual([])
}) // end table
expect(TestTable).toEqual(expect.objectContaining({
name: 'test-table',
Table: expect.objectContaining({
partitionKey: 'pk',
sortKey: null,
entityField: '_et',
indexes: {},
attributes: { _et: { type: 'string', mappings: {} } }
}),
autoExecute: true,
autoParse: true,
entities: []
}))
})

it('creates table w/ options', async () => {
const TestTable = new Table({
Expand All @@ -30,17 +33,20 @@ describe('Table creation', () => {
autoParse: false
})

expect(TestTable instanceof Table).toBe(true)
expect(TestTable.name).toBe('test-table')
expect(TestTable.Table.partitionKey).toBe('pk')
expect(TestTable.Table.sortKey).toBe('sk')
expect(TestTable.Table.entityField).toBe('entity')
expect(TestTable.Table.indexes).toEqual({})
expect(TestTable.Table.attributes).toEqual({ entity: { type: 'string', mappings: {} } })
expect(TestTable.autoExecute).toBe(false)
expect(TestTable.autoParse).toBe(false)
expect(TestTable.entities).toEqual([])
}) // end table w/ options
expect(TestTable).toEqual(expect.objectContaining({
name: 'test-table',
Table: expect.objectContaining({
partitionKey: 'pk',
sortKey: 'sk',
entityField: 'entity',
indexes: {},
attributes: { entity: { type: 'string', mappings: {} } }
}),
autoExecute: false,
autoParse: false,
entities: []
}))
})

it('creates table w/ attributes', async () => {
const TestTable = new Table({
Expand All @@ -59,65 +65,62 @@ describe('Table creation', () => {
}
})

expect(TestTable instanceof Table).toBe(true)
expect(TestTable.name).toBe('test-table')
expect(TestTable.Table.partitionKey).toBe('pk')
expect(TestTable.Table.sortKey).toBeNull()
expect(TestTable.Table.entityField).toBe('_et')
expect(TestTable.Table.indexes).toEqual({})
expect(TestTable.autoExecute).toBe(true)
expect(TestTable.autoParse).toBe(true)
expect(TestTable.entities).toEqual([])

// Check attribute parsing
expect(TestTable.Table.attributes).toEqual({
stringAttr: { type: 'string', mappings: {} },
numberAttr: { type: 'number', mappings: {} },
binaryAttr: { type: 'binary', mappings: {} },
booleanAttr: { type: 'boolean', mappings: {} },
listAttr: { type: 'list', mappings: {} },
mapAttr: { type: 'map', mappings: {} },
stringSetAttr: { type: 'set', mappings: {} },
numberSetAttr: { type: 'set', setType: 'number', mappings: {} },
binarySetAttr: { type: 'set', setType: 'binary', mappings: {} },
_et: { type: 'string', mappings: {} }
})
}) // end table w/ attributes
expect(TestTable).toEqual(expect.objectContaining({
name: 'test-table',
Table: expect.objectContaining({
partitionKey: 'pk',
sortKey: null,
entityField: '_et',
indexes: {},
attributes: {
stringAttr: { type: 'string', mappings: {} },
numberAttr: { type: 'number', mappings: {} },
binaryAttr: { type: 'binary', mappings: {} },
booleanAttr: { type: 'boolean', mappings: {} },
listAttr: { type: 'list', mappings: {} },
mapAttr: { type: 'map', mappings: {} },
stringSetAttr: { type: 'set', mappings: {} },
numberSetAttr: { type: 'set', setType: 'number', mappings: {} },
binarySetAttr: { type: 'set', setType: 'binary', mappings: {} },
_et: { type: 'string', mappings: {} }
}
})
}))
})

it('creates table w/ indexes', async () => {
const TestTable = new Table({
name: 'test-table',
partitionKey: 'pk',
indexes: {
// GSI w/ pk and sk
GSI1: { partitionKey: 'GSI1pk', sortKey: 'GSI1sk' },
// GSI w/ only pk
GSI2: { partitionKey: 'GSI2pk' },
// LSI w/ reused pk
LSI1: { partitionKey: 'pk', sortKey: 'LSI1sk' },
// LSI w/ only sk
LSI2: { sortKey: 'LSI2sk' }
}
})

expect(TestTable instanceof Table).toBe(true)
expect(TestTable.name).toBe('test-table')
expect(TestTable.Table.partitionKey).toBe('pk')
expect(TestTable.Table.sortKey).toBeNull()
expect(TestTable.Table.entityField).toBe('_et')
expect(TestTable.Table.attributes).toEqual({ _et: { type: 'string', mappings: {} } })
expect(TestTable.autoExecute).toBe(true)
expect(TestTable.autoParse).toBe(true)
expect(TestTable.entities).toEqual([])

// Verify index parsing
expect(TestTable.Table.indexes).toEqual({
GSI1: { partitionKey: 'GSI1pk', sortKey: 'GSI1sk', type: 'GSI' },
GSI2: { partitionKey: 'GSI2pk', type: 'GSI' },
LSI1: { sortKey: 'LSI1sk', type: 'LSI' },
LSI2: { sortKey: 'LSI2sk', type: 'LSI' }
})
}) // end table w/ indexes
expect(TestTable).toEqual(expect.objectContaining({
name: 'test-table',
Table: expect.objectContaining({
partitionKey: 'pk',
sortKey: null,
entityField: '_et',
indexes: {
GSI1: { partitionKey: 'GSI1pk', sortKey: 'GSI1sk', type: 'GSI' },
GSI2: { partitionKey: 'GSI2pk', type: 'GSI' },
LSI1: { sortKey: 'LSI1sk', type: 'LSI' },
LSI2: { sortKey: 'LSI2sk', type: 'LSI' }
},
attributes: {
_et: { type: 'string', mappings: {} }
},
}),
autoExecute: true,
autoParse: true,
entities: [],
}))
})

it('creates table w/ DocumentClient', async () => {
const TestTable = new Table({
Expand All @@ -126,38 +129,43 @@ describe('Table creation', () => {
DocumentClient
})

expect(TestTable instanceof Table).toBe(true)
expect(TestTable.DocumentClient!.constructor.name).toBe('DynamoDBDocumentClient')
expect(TestTable.name).toBe('test-table')
expect(TestTable.Table.partitionKey).toBe('pk')
expect(TestTable.Table.sortKey).toBeNull()
expect(TestTable.Table.entityField).toBe('_et')
expect(TestTable.Table.indexes).toEqual({})
expect(TestTable.Table.attributes).toEqual({ _et: { type: 'string', mappings: {} } })
expect(TestTable.autoExecute).toBe(true)
expect(TestTable.autoParse).toBe(true)
expect(TestTable.entities).toEqual([])
}) // end create table w/ DocumentClient
expect(TestTable.DocumentClient.constructor.name).toBe('DynamoDBDocumentClient')
expect(TestTable).toEqual(expect.objectContaining({
name: 'test-table',
Table: expect.objectContaining({
partitionKey: 'pk',
sortKey: null,
entityField: '_et',
indexes: {},
attributes: { _et: { type: 'string', mappings: {} } },
}),
autoExecute: true,
autoParse: true,
entities: [],
}))
})

it('creates table, then add DocumentClient', async () => {
const TestTable = new Table({
name: 'test-table',
partitionKey: 'pk'
})

// Add the DocumentClient
TestTable.DocumentClient = DocumentClient

expect(TestTable instanceof Table).toBe(true)
expect(TestTable.DocumentClient.constructor.name).toBe('DynamoDBDocumentClient')
expect(TestTable.name).toBe('test-table')
expect(TestTable.Table.partitionKey).toBe('pk')
expect(TestTable.Table.sortKey).toBeNull()
expect(TestTable.Table.entityField).toBe('_et')
expect(TestTable.Table.indexes).toEqual({})
expect(TestTable.Table.attributes).toEqual({ _et: { type: 'string', mappings: {} } })
expect(TestTable.autoExecute).toBe(true)
expect(TestTable.autoParse).toBe(true)
expect(TestTable.entities).toEqual([])
}) // end create table w/ DocumentClient
expect(TestTable).toEqual(expect.objectContaining({
name: 'test-table',
Table: expect.objectContaining({
partitionKey: 'pk',
sortKey: null,
entityField: '_et',
indexes: {},
attributes: { _et: { type: 'string', mappings: {} } },
}),
entities: [],
autoExecute: true,
autoParse: true,
}))
})
})
Loading

0 comments on commit 82391ea

Please sign in to comment.