-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
8 changed files
with
118 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { timeouts } from "../common"; | ||
|
||
type CountResult = { count: number, ids: string[] }; | ||
|
||
type FragmentInfo = { _id: string, nrOfMembersAdded: number } | ||
type DocumentResult = { count: number, documents: FragmentInfo[] }; | ||
|
||
export class PostgresRestApi { | ||
|
||
constructor(public baseUrl: string) { } | ||
|
||
checkCount(collection: string, count: number, checkFn: (actual: number, expected: number) => boolean = (x, y) => x === y) { | ||
return cy.waitUntil(() => this.hasCount(collection, count, checkFn), { timeout: timeouts.slowAction, interval: timeouts.slowCheck, errorMsg: `Timed out waiting for document collection '${collection}' to correctly compare to ${count}` }); | ||
} | ||
|
||
checkFragmentMemberCount(fragment: string, count: number, checkFn: (actual: number, expected: number) => boolean = (x, y) => x === y) { | ||
return cy.waitUntil(() => this.hasFragmentMemberCount(fragment, count, checkFn), { timeout: timeouts.slowAction, interval: timeouts.slowCheck, errorMsg: `Timed out waiting for fragment member count of '${fragment}' to correctly compare to ${count}` }); | ||
} | ||
|
||
private hasFragmentMemberCount(fragment: string, count: number, checkFn: (actual: number, expected: number) => boolean) { | ||
return cy.request(`${this.baseUrl}/fragmentation_fragment?includeDocuments=true`) | ||
.then(response => response.body) | ||
.then((body: DocumentResult) => body.documents.find(x => x._id === fragment)) | ||
.then((fragment: FragmentInfo) => cy.log('Actual fragment member count: ' + fragment.nrOfMembersAdded).then(() => checkFn(fragment.nrOfMembersAdded , count))); | ||
} | ||
|
||
private hasCount(collection: string, count: number, checkFn: (actual: number, expected: number) => boolean) { | ||
return cy.request(`${this.baseUrl}/${collection}`) | ||
.then(response => response.body) | ||
.then((result: CountResult) => cy.log('Actual count: ' + result.count).then(() => checkFn(result.count , count))); | ||
} | ||
|
||
count(collection: string) { | ||
return cy.request(`${this.baseUrl}/${collection}`) | ||
.then(response => response.body) | ||
.then((result: CountResult) => result.count); | ||
} | ||
|
||
private documentIds(document: string) { | ||
return cy.request(`${this.baseUrl}/${document}?includeIds=true`) | ||
.then(response => response.body && (response.body.ids as string[])); | ||
} | ||
} |
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
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