0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/packages/api/test/integration/whoami.spec.ts
Juan Picado 06f68eb0e7
chore: migrate vitest packages (#4780)
* chore: migrate api package

* Update distTag.spec.ts

* fix storage test

* Update server.ts

* migrate search package

* chore: migrate plugin local-storage
2024-08-04 20:17:02 +02:00

36 lines
1.3 KiB
TypeScript

import supertest from 'supertest';
import { describe, expect, test } from 'vitest';
import { HEADERS, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/core';
import { buildToken } from '@verdaccio/utils';
import { createUser, initializeServer } from './_helper';
describe('whoami', () => {
test('should return the logged username', async () => {
const app = await initializeServer('whoami.yaml');
// @ts-expect-error internal property
const { _body } = await createUser(app, 'test', 'test');
return supertest(app)
.get('/-/whoami')
.set('Accept', HEADERS.JSON)
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, _body.token))
.expect('Content-Type', HEADERS.JSON_CHARSET)
.expect(HTTP_STATUS.OK)
.then((response) => {
expect(response.body.username).toEqual('test');
});
});
test('should fails with 401 if is not logged in', async () => {
const app = await initializeServer('whoami.yaml');
// @ts-expect-error internal property
const { _body } = await createUser(app, 'test', 'test');
return supertest(app)
.get('/-/whoami')
.set('Accept', HEADERS.JSON)
.set(HEADERS.AUTHORIZATION, buildToken('invalid-token', _body.token))
.expect('Content-Type', HEADERS.JSON_CHARSET)
.expect(HTTP_STATUS.UNAUTHORIZED);
});
});