Skip to content

Commit

Permalink
feat: use limax instead of slug
Browse files Browse the repository at this point in the history
  • Loading branch information
vinz243 committed Apr 15, 2018
1 parent 9329764 commit 43d62c3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 55 deletions.
100 changes: 78 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@
"validate-commit-msg": "^2.12.2"
},
"dependencies": {
"slug": "^0.9.1"
"limax": "^1.6.0"
}
}
3 changes: 2 additions & 1 deletion src/decorators/SlothEntity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import BaseEntity from '../models/BaseEntity'
import SlothData from '../models/SlothData'
import slug from 'slug'
import StaticData from '../models/StaticData'
import PouchFactory from '../models/PouchFactory'
import EntityConstructor from '../helpers/EntityConstructor'
import getProtoData from '../utils/getProtoData'

const slug = require('limax')

/**
* This decorator is used to mark classes that will be an entity, a document
* This function, by extending the constructor and defining this.sloth property
Expand Down
52 changes: 26 additions & 26 deletions test/integration/Album.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('generate uri', async () => {
artist: flatbushZombies._id
})

expect(betterOffDead._id).toBe('library/Flatbush-Zombies/BetterOffDead')
expect(betterOffDead._id).toBe('library/flatbush-zombies/betteroffdead')
})

test('updated uri', async () => {
Expand All @@ -37,11 +37,11 @@ test('updated uri', async () => {
name: 'BetterOffDead',
artist: 'library/flatbush'
})
expect(betterOffDead._id).toBe('library/flatbush/BetterOffDead')
expect(betterOffDead._id).toBe('library/flatbush/betteroffdead')

betterOffDead.artist = 'library/Flatbush-Zombies'
betterOffDead.artist = 'library/flatbush-zombies'

expect(betterOffDead._id).toBe('library/Flatbush-Zombies/BetterOffDead')
expect(betterOffDead._id).toBe('library/flatbush-zombies/betteroffdead')
})

test('remove parent if last child is removed', async () => {
Expand All @@ -61,22 +61,22 @@ test('remove parent if last child is removed', async () => {

await betterOffDead.save()

expect(await db.get('library/Flatbush-Zombies/BetterOffDead')).toMatchObject({
_id: 'library/Flatbush-Zombies/BetterOffDead',
artist: 'library/Flatbush-Zombies'
expect(await db.get('library/flatbush-zombies/betteroffdead')).toMatchObject({
_id: 'library/flatbush-zombies/betteroffdead',
artist: 'library/flatbush-zombies'
})

expect(await db.get('library/Flatbush-Zombies')).toMatchObject({
_id: 'library/Flatbush-Zombies',
expect(await db.get('library/flatbush-zombies')).toMatchObject({
_id: 'library/flatbush-zombies',
name: 'Flatbush Zombies'
})

await betterOffDead.remove()
await expect(db.get('library/Flatbush-Zombies')).rejects.toMatchObject({
await expect(db.get('library/flatbush-zombies')).rejects.toMatchObject({
message: 'missing'
})
await expect(
db.get('library/Flatbush-Zombies/BetterOffDead')
db.get('library/flatbush-zombies/betteroffdead')
).rejects.toMatchObject({ message: 'missing' })
})

Expand Down Expand Up @@ -104,39 +104,39 @@ test('doesnt remove parent if still has children', async () => {

await vacationInHell.save()

expect(await db.get('library/Flatbush-Zombies/BetterOffDead')).toMatchObject({
_id: 'library/Flatbush-Zombies/BetterOffDead',
artist: 'library/Flatbush-Zombies'
expect(await db.get('library/flatbush-zombies/betteroffdead')).toMatchObject({
_id: 'library/flatbush-zombies/betteroffdead',
artist: 'library/flatbush-zombies'
})

expect(
await db.get('library/Flatbush-Zombies/Vacation-In-Hell')
await db.get('library/flatbush-zombies/vacation-in-hell')
).toMatchObject({
_id: 'library/Flatbush-Zombies/Vacation-In-Hell',
artist: 'library/Flatbush-Zombies'
_id: 'library/flatbush-zombies/vacation-in-hell',
artist: 'library/flatbush-zombies'
})

expect(await db.get('library/Flatbush-Zombies')).toMatchObject({
_id: 'library/Flatbush-Zombies',
expect(await db.get('library/flatbush-zombies')).toMatchObject({
_id: 'library/flatbush-zombies',
name: 'Flatbush Zombies'
})

await betterOffDead.remove()

expect(
await db.get('library/Flatbush-Zombies/Vacation-In-Hell')
await db.get('library/flatbush-zombies/vacation-in-hell')
).toMatchObject({
_id: 'library/Flatbush-Zombies/Vacation-In-Hell',
artist: 'library/Flatbush-Zombies'
_id: 'library/flatbush-zombies/vacation-in-hell',
artist: 'library/flatbush-zombies'
})

expect(await db.get('library/Flatbush-Zombies')).toMatchObject({
_id: 'library/Flatbush-Zombies',
expect(await db.get('library/flatbush-zombies')).toMatchObject({
_id: 'library/flatbush-zombies',
name: 'Flatbush Zombies'
})

await expect(
db.get('library/Flatbush-Zombies/BetterOffDead')
db.get('library/flatbush-zombies/betteroffdead')
).rejects.toMatchObject({ message: 'missing' })
})

Expand All @@ -157,6 +157,6 @@ test('rels.artist - maps with artist', async () => {

const flatbush = await betterOffDead.rels.artist(factory)

expect(flatbush._id).toBe('library/Flatbush-Zombies')
expect(flatbush._id).toBe('library/flatbush-zombies')
expect(flatbush.name).toBe('Flatbush Zombies')
})
8 changes: 4 additions & 4 deletions test/integration/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('nested objects', () => {
barz: 'foobarbarz'
}
})
expect(await factory('foos').get('foos/Foobar')).toMatchObject({
expect(await factory('foos').get('foos/foobar')).toMatchObject({
name: 'Foobar',
foo: {
bar: 'foobar',
Expand All @@ -59,15 +59,15 @@ describe('nested objects', () => {
})

test('get a document with a nested doc', async () => {
const { foo } = await Foo.findById(factory, 'foos/Foobar')
const { foo } = await Foo.findById(factory, 'foos/foobar')
expect(foo).toEqual({
bar: 'foobar',
barz: 'foobarbarz'
})
})

test('update a document with a nested doc', async () => {
const foo = await Foo.findById(factory, 'foos/Foobar')
const foo = await Foo.findById(factory, 'foos/foobar')

foo.foo = { bar: 'bar', barz: 'barz' }

Expand All @@ -78,7 +78,7 @@ describe('nested objects', () => {

await foo.save()

expect(await factory('foos').get('foos/Foobar')).toMatchObject({
expect(await factory('foos').get('foos/foobar')).toMatchObject({
name: 'Foobar',
foo: {
bar: 'bar',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/decorators/SlothURI.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SlothURI from '../../../src/decorators/SlothURI'
import emptyProtoData from '../../utils/emptyProtoData'
import slug from 'slug'
const slug = require('limax')

test('SlothURI - returns correct url', () => {
const object = {
Expand Down

0 comments on commit 43d62c3

Please sign in to comment.