-
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.
Browse files
Browse the repository at this point in the history
…ert-system #23 Upsert System
- Loading branch information
Showing
3 changed files
with
70 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,58 @@ | ||
import prisma from '../src/prisma/prisma-client'; | ||
import { describe, test, expect } from 'vitest'; | ||
import { describe, test, expect, afterAll } from 'vitest'; | ||
import { getAllSystems, upsertSystems } from '../src/services/systems.services'; | ||
|
||
/** | ||
* Tests for CRUD service functions | ||
*/ | ||
import prisma from '../src/prisma/prisma-client'; | ||
|
||
/** | ||
* basic ahh unit test for get all systems | ||
* Tests for CRUD Service functions | ||
*/ | ||
describe('CRUD Systems', () => { | ||
/** | ||
* unit test for upsert system | ||
* testing creating system if doesn't exist | ||
*/ | ||
test('Upsert System Creates', async () => { | ||
const expected = [{ name: 'test' }]; | ||
await upsertSystems('test'); | ||
const result = JSON.parse(await getAllSystems()); | ||
|
||
// Use toEqual to compare parsedResult with the expected array | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
/** | ||
* updated unit test for get all systems | ||
*/ | ||
test('Get All Systems Works', async () => { | ||
const allSystems = await prisma.system.findMany(); | ||
expect(allSystems).toStrictEqual([]); | ||
const expected = [{ name: 'test' }]; | ||
const result = await getAllSystems(); | ||
|
||
// Parse result to a JavaScript object from the JSON string | ||
const parsedResult = JSON.parse(result); | ||
|
||
// Use toEqual to compare parsedResult with the expected array | ||
expect(parsedResult).toEqual(expected); | ||
}); | ||
|
||
/** | ||
* unit test for upsert system | ||
* testing does nothing if system does exist | ||
*/ | ||
test('Upsert System Does Nothing', async () => { | ||
const expected = [{ name: 'test' }]; | ||
await upsertSystems('test'); | ||
const result = JSON.parse(await getAllSystems()); | ||
|
||
// Use toEqual to compare result with the expected array | ||
expect(result).toEqual(expected); | ||
|
||
//cleaning up | ||
afterAll(async () => { | ||
await prisma.system.delete({ | ||
where: { | ||
name: 'test' | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |