0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00
verdaccio/test/unit/modules/api/whoami.spec.ts
Juan Picado bae430fe24
feat: refactor test and use verdaccio 6 core modules (#3569)
chore: clean up comments

remove commitlint

update deps

add new tests

test

separate ci

test

test

test

test

test

test

chore: add preprelase

test

test

test

test

test

chore: update deps

Update release-snapshot.yml

Update .npmignore

test

chore: remove @verdaccio/commons-api dep

chore: cleanup

remove normalizeContributors

remove validateMetadata

fix test

clean up getLocalRegistryTarballUri

Update store.spec.ts

clean up convertDistRemoteToLocalTarballUrls

chore: update libraries

reuse getPublic url

clean up

Update jest.config.js

Update jest.config.js

update nvmrc

add tests
2023-01-28 14:39:37 +01:00

35 lines
1.3 KiB
TypeScript

import supertest from 'supertest';
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.skip('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);
});
});