-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1603: Feat/snapshots r=brunoocasali a=brunoocasali Add the ability to create snapshots according to the v1.5 spec. Co-authored-by: Bruno Casali <[email protected]>
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 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,70 @@ | ||
import { ErrorStatusCode } from '../src/types' | ||
import { | ||
clearAllIndexes, | ||
config, | ||
MeiliSearch, | ||
BAD_HOST, | ||
getClient, | ||
} from './utils/meilisearch-test-utils' | ||
|
||
beforeEach(async () => { | ||
await clearAllIndexes(config) | ||
}) | ||
|
||
describe.each([{ permission: 'Master' }, { permission: 'Admin' }])( | ||
'Test on snapshot', | ||
({ permission }) => { | ||
test(`${permission} key: create a new snapshot`, async () => { | ||
const client = await getClient(permission) | ||
const { taskUid } = await client.createSnapshot() | ||
|
||
await client.waitForTask(taskUid) | ||
}) | ||
} | ||
) | ||
|
||
describe.each([{ permission: 'Search' }])( | ||
'Test on snapshot with search api key should not have access', | ||
({ permission }) => { | ||
test(`${permission} key: try to create snapshot with search key and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect(client.createSnapshot()).rejects.toHaveProperty( | ||
'code', | ||
ErrorStatusCode.INVALID_API_KEY | ||
) | ||
}) | ||
} | ||
) | ||
|
||
describe.each([{ permission: 'No' }])( | ||
'Test on snapshot without api key should not have access', | ||
({ permission }) => { | ||
test(`${permission} key: try to create snapshot with no key and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect(client.createSnapshot()).rejects.toHaveProperty( | ||
'code', | ||
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER | ||
) | ||
}) | ||
} | ||
) | ||
|
||
describe.each([ | ||
{ host: BAD_HOST, trailing: false }, | ||
{ host: `${BAD_HOST}/api`, trailing: false }, | ||
{ host: `${BAD_HOST}/trailing/`, trailing: true }, | ||
])('Tests on url construction', ({ host, trailing }) => { | ||
test(`Test createSnapshot route`, async () => { | ||
const route = `snapshots` | ||
const client = new MeiliSearch({ host }) | ||
const strippedHost = trailing ? host.slice(0, -1) : host | ||
|
||
await expect(client.createSnapshot()).rejects.toHaveProperty( | ||
'message', | ||
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( | ||
'http://', | ||
'' | ||
)}` | ||
) | ||
}) | ||
}) |