-
Notifications
You must be signed in to change notification settings - Fork 14
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
31 changed files
with
481 additions
and
187 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import type { Server } from 'http'; | ||
|
||
import { expect } from 'chai'; | ||
import type { Express } from 'express'; | ||
|
||
import { setupServer } from '.'; | ||
|
||
const retryCount: Record< | ||
string, | ||
{ | ||
add: number; | ||
update: number; | ||
delete: number; | ||
} | ||
> = {}; | ||
|
||
export function assertValidWaitForApiKey(expectedCount: number): void { | ||
expect(Object.keys(retryCount).length).to.be.equal(expectedCount); | ||
for (const retry of Object.values(retryCount)) { | ||
expect(retry).to.deep.equal({ | ||
add: 0, | ||
update: 0, | ||
delete: 0, | ||
}); | ||
} | ||
} | ||
|
||
function addRoutes(app: Express): void { | ||
app.get('/1/keys/:key', (req, res) => { | ||
const lang = req.params.key.split('-').at(-1) as string; | ||
if (!retryCount[lang]) { | ||
retryCount[lang] = { | ||
add: 0, | ||
update: 0, | ||
delete: 0, | ||
}; | ||
} | ||
const retry = retryCount[lang]; | ||
if (req.params.key === `api-key-add-operation-test-${lang}`) { | ||
if (retry.add < 3) { | ||
res.status(404).json({ message: `API key doesn't exist` }); | ||
} else if (retry.add === 3) { | ||
res.status(200).json({ | ||
value: req.params.key, | ||
description: 'my new api key', | ||
acl: ['search', 'addObject'], | ||
validity: 300, | ||
maxQueriesPerIPPerHour: 100, | ||
maxHitsPerQuery: 20, | ||
createdAt: 1720094400, | ||
}); | ||
|
||
retry.add = -1; | ||
} else { | ||
expect(retry.add).to.be.lessThan(3); | ||
return; | ||
} | ||
|
||
retry.add += 1; | ||
} else if (req.params.key === `api-key-update-operation-test-${lang}`) { | ||
if (retry.update < 3) { | ||
res.status(200).json({ | ||
value: req.params.key, | ||
description: 'my new api key', | ||
acl: ['search', 'addObject'], | ||
validity: 300, | ||
maxQueriesPerIPPerHour: 100, | ||
maxHitsPerQuery: 20, | ||
createdAt: 1720094400, | ||
}); | ||
} else if (retry.update === 3) { | ||
res.status(200).json({ | ||
value: req.params.key, | ||
description: 'my updated api key', | ||
acl: ['search', 'addObject', 'deleteObject'], | ||
indexes: ['Movies', 'Books'], | ||
referers: ['*google.com', '*algolia.com'], | ||
validity: 305, | ||
maxQueriesPerIPPerHour: 95, | ||
maxHitsPerQuery: 20, | ||
createdAt: 1720094400, | ||
}); | ||
|
||
retry.update = -1; | ||
} else { | ||
expect(retry.update).to.be.lessThan(3); | ||
return; | ||
} | ||
|
||
retry.update += 1; | ||
} else if (req.params.key === `api-key-delete-operation-test-${lang}`) { | ||
if (retry.delete < 3) { | ||
res.status(200).json({ | ||
value: req.params.key, | ||
description: 'my updated api key', | ||
acl: ['search', 'addObject', 'deleteObject'], | ||
validity: 305, | ||
maxQueriesPerIPPerHour: 95, | ||
maxHitsPerQuery: 20, | ||
createdAt: 1720094400, | ||
}); | ||
} else if (retry.delete === 3) { | ||
res.status(404).json({ message: `API key doesn't exist` }); | ||
|
||
retry.delete = -1; | ||
} else { | ||
expect(retry.delete).to.be.lessThan(3); | ||
return; | ||
} | ||
|
||
retry.delete += 1; | ||
} else { | ||
throw new Error(`Invalid API key ${req.params.key}`); | ||
} | ||
}); | ||
} | ||
|
||
export function waitForApiKeyServer(): Promise<Server> { | ||
return setupServer('waitForApiKey', 6681, addRoutes); | ||
} |
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
Oops, something went wrong.