-
-
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.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
31f009c
commit b11e17d
Showing
10 changed files
with
286 additions
and
97 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @file Type Tests - construct | ||
* @module tutils/utils/tests/unit-d/construct | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import type { Construct, Crush } from '#src/types' | ||
import type testSubject from '../construct' | ||
|
||
describe('unit-d:utils/construct', () => { | ||
it('should return Construct<T>', () => { | ||
// Arrange | ||
type T = Crush<Vehicle & { driver: { nanoid: string } }> | ||
|
||
// Expect | ||
expectTypeOf<typeof testSubject<T>>().returns.toEqualTypeOf<Construct<T>>() | ||
}) | ||
}) |
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,31 @@ | ||
/** | ||
* @file Unit Tests - construct | ||
* @module tutils/utils/tests/unit/construct | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import testSubject from '../construct' | ||
|
||
describe('unit:utils/construct', () => { | ||
let obj: Vehicle & { 'driver.nanoid': string } | ||
|
||
beforeAll(() => { | ||
obj = { | ||
'driver.nanoid': faker.string.nanoid(), | ||
make: faker.vehicle.manufacturer(), | ||
model: faker.vehicle.model(), | ||
vin: faker.vehicle.vin(), | ||
year: faker.date.past({ years: 3 }).getFullYear() | ||
} | ||
}) | ||
|
||
it('should return reconstructed object', () => { | ||
expect(testSubject(obj)).to.deep.equal({ | ||
driver: { nanoid: obj['driver.nanoid'] }, | ||
make: obj.make, | ||
model: obj.model, | ||
vin: obj.vin, | ||
year: obj.year | ||
}) | ||
}) | ||
}) |
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,18 @@ | ||
/** | ||
* @file Type Tests - crush | ||
* @module tutils/utils/tests/unit-d/crush | ||
*/ | ||
|
||
import type Book from '#fixtures/interfaces/book' | ||
import type { Crush } from '#src/types' | ||
import type testSubject from '../crush' | ||
|
||
describe('unit-d:utils/crush', () => { | ||
it('should return Crush<T>', () => { | ||
// Arrange | ||
type T = Book | ||
|
||
// Expect | ||
expectTypeOf<typeof testSubject<T>>().returns.toEqualTypeOf<Crush<T>>() | ||
}) | ||
}) |
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,60 @@ | ||
/** | ||
* @file Unit Tests - crush | ||
* @module tutils/utils/tests/unit/crush | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import VEHICLE from '#fixtures/vehicle' | ||
import type { ObjectCurly } from '#src/types' | ||
import testSubject from '../crush' | ||
import isObjectPlain from '../is-object-plain' | ||
|
||
describe('unit:utils/crush', () => { | ||
let array: [Vehicle] | ||
let pojo: Vehicle & { driver: { nanoid: string }; riders: { uuid: string }[] } | ||
|
||
beforeAll(() => { | ||
array = [VEHICLE] | ||
pojo = { | ||
...VEHICLE, | ||
driver: { nanoid: faker.string.nanoid() }, | ||
riders: [{ uuid: faker.string.uuid() }, { uuid: faker.string.uuid() }] | ||
} | ||
}) | ||
|
||
it('should return one-dimensional plain object', () => { | ||
// Arrange | ||
const cases: [...Parameters<typeof testSubject>, ObjectCurly][] = [ | ||
[null, {}], | ||
[undefined, {}], | ||
[ | ||
array, | ||
{ | ||
'0.make': array[0].make, | ||
'0.model': array[0].model, | ||
'0.vin': array[0].vin, | ||
'0.year': array[0].year | ||
} | ||
], | ||
[ | ||
pojo, | ||
{ | ||
'driver.nanoid': pojo.driver.nanoid, | ||
make: pojo.make, | ||
model: pojo.model, | ||
'riders.0.uuid': pojo.riders[0]!.uuid, | ||
'riders.1.uuid': pojo.riders[1]!.uuid, | ||
vin: pojo.vin, | ||
year: pojo.year | ||
} | ||
] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([obj, expected]) => { | ||
expect(testSubject(obj)) | ||
.to.deep.equal(expected) | ||
.and.satisfy(isObjectPlain) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.