-
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.
- Loading branch information
1 parent
fc93a63
commit d7f463f
Showing
251 changed files
with
59,324 additions
and
98 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,130 @@ | ||
import {xdescribe, expect, test} from '@jest/globals'; | ||
import {CarbonReact} from "@carbonorm/carbonreact"; | ||
import {checkAllRequestsComplete} from "@carbonorm/carbonnode"; | ||
import {act, waitFor} from '@testing-library/react'; | ||
import {C6, iRestfulObjectArrayTypes, iDocumentation, documentation } from "api/rest/C6"; | ||
import Documentation from "./Documentation"; | ||
|
||
const randomString = Math.random().toString(36).substring(7); | ||
const randomInt = Math.floor(Math.random() * 1000000); | ||
const fillString = 'string' + randomString + randomInt; | ||
|
||
console.log('fillString', fillString); | ||
|
||
/** | ||
CREATE TABLE `carbon_documentation` ( | ||
`documentation_uri` varchar(255) NOT NULL, | ||
`documentation_data` longblob, | ||
`documentation_version` varchar(40) NOT NULL, | ||
`documentation_active` tinyint NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; | ||
**/ | ||
|
||
const Test_Data: iDocumentation = { | ||
|
||
documentation_data: fillString.substring(0, ), | ||
|
||
} | ||
|
||
export default Test_Data; | ||
|
||
xdescribe('REST Documentation api', () => { | ||
|
||
let testData = Test_Data; | ||
|
||
test('GET POST PUT DELETE', async () => { | ||
|
||
await act(async () => { | ||
|
||
let selectAllResponse = await Documentation.Get({}) | ||
|
||
if ('function' === typeof selectAllResponse) { | ||
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.'); | ||
} | ||
|
||
// We don't care if it is filled or not, just that the request can be made. | ||
expect(selectAllResponse?.data?.rest).not.toBeUndefined(); | ||
|
||
const postResponse = await Documentation.Post(testData); | ||
|
||
console.log('postResponse', postResponse?.data) | ||
|
||
expect(postResponse?.data?.created).not.toBeUndefined(); | ||
|
||
const primaryKey = documentation.PRIMARY_SHORT[0]; | ||
|
||
const postID = postResponse?.data?.created | ||
|
||
const singleRowSelect = await Documentation.Get({ | ||
[C6.WHERE]: { | ||
[documentation[primaryKey.toUpperCase()]]: postID, | ||
} | ||
}) | ||
|
||
if ('function' === typeof singleRowSelect) { | ||
throw Error('singleRowSelect is a promise, this is unexpected.'); | ||
} | ||
|
||
console.log('singleRowSelect', singleRowSelect?.data) | ||
|
||
// Ensure the expected response datastructure is returned | ||
expect(singleRowSelect?.data?.rest).not.toBeUndefined(); | ||
|
||
// Make sure the previously created post is now returned | ||
expect(typeof singleRowSelect?.data?.rest).toEqual('object'); | ||
|
||
// todo - make this work correctly with multiple primary keys | ||
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey] | ||
|
||
expect(selectedPostId).toEqual(postID); | ||
|
||
const multipleRowSelect = await Documentation.Get({ | ||
[C6.WHERE]: { | ||
[documentation[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]], | ||
} | ||
}) | ||
|
||
if ('function' === typeof multipleRowSelect) { | ||
throw Error('singleRowSelect is a promise, this is unexpected.'); | ||
} | ||
|
||
console.log('singleRowSelect', multipleRowSelect?.data) | ||
|
||
// Ensure the expected response datastructure is returned | ||
expect(multipleRowSelect?.data?.rest).not.toBeUndefined(); | ||
|
||
// Make sure the previously created post is now returned | ||
expect(typeof multipleRowSelect?.data?.rest).toEqual('object'); | ||
|
||
testData[primaryKey] = postID | ||
|
||
testData.documentation_uri = fillString.substring(0, 255); | ||
testData.documentation_data = fillString.substring(0, ); | ||
testData.documentation_version = fillString.substring(0, 40); | ||
testData.documentation_active = randomInt; | ||
|
||
// wait for the global state to be updated | ||
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().documentation).not.toBeUndefined(); | ||
|
||
const updateResponse = await Documentation.Put(testData) | ||
|
||
expect(updateResponse?.data?.updated).not.toBeUndefined(); | ||
|
||
const deleteResponse = await Documentation.Delete({ | ||
[primaryKey]: postID | ||
}) | ||
|
||
console.log('deleteResponse', deleteResponse?.data) | ||
|
||
expect(deleteResponse?.data?.deleted).not.toBeUndefined(); | ||
|
||
await waitFor(async () => { | ||
expect(checkAllRequestsComplete()).toEqual(true); | ||
}, {timeout: 10000, interval: 1000}); | ||
|
||
}) | ||
|
||
}, 100000); | ||
|
||
}) | ||
|
Oops, something went wrong.