Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add unit tests #74

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 55 additions & 45 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

littlespex marked this conversation as resolved.
Show resolved Hide resolved
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!--
## [VERSION] - DATE
### Added
Expand All @@ -18,177 +20,185 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.6.2] - 2024-02-21

### Added

- Unit tests for id3 feature helper functions [#74](https://github.com/streaming-video-technology-alliance/common-media-library/pull/74)
littlespex marked this conversation as resolved.
Show resolved Hide resolved

## [0.6.2] - 2023-01-18

### Fixed
- Some imports are pulling in unnecessary files [#64](https://github.com/streaming-video-technology-alliance/common-media-library/issues/64)

- Some imports are pulling in unnecessary files [#64](https://github.com/streaming-video-technology-alliance/common-media-library/issues/64)

## [0.6.1] - 2023-12-14

### Fixed
- Incorrect return type for `decodeCmsdDynamic` function [#55](https://github.com/streaming-video-technology-alliance/common-media-library/issues/55)

- Incorrect return type for `decodeCmsdDynamic` function [#55](https://github.com/streaming-video-technology-alliance/common-media-library/issues/55)

## [0.6.0] - 2023-11-29

### Added

- Add the ability to pass a base URL to all CMCD encode utilities to construct relative paths for `nor` [#50](https://github.com/streaming-video-technology-alliance/common-media-library/issues/50)
- Export constants for CMCD and CMSD version numbers [#44](https://github.com/streaming-video-technology-alliance/common-media-library/issues/44)

### Fixed

- CMCD does not protect against non-Finite numeric values [#45](https://github.com/streaming-video-technology-alliance/common-media-library/issues/45)
- `appendCmcdQuery` does not account for existing CMCD query params [#48](https://github.com/streaming-video-technology-alliance/common-media-library/issues/48)


## [0.5.1] - 2023-11-16

### Changed
- Remove `BigInt` notation

- Remove `BigInt` notation

## [0.5.0] - 2023-11-14

### Added

- Implement Common Media Server Data (CMSD) utilities [#35](https://github.com/streaming-video-technology-alliance/common-media-library/issues/35)
- Add request and response interceptors API


## [0.4.5] - 2023-10-12

### Fixed

- `CMCD_PARAM` constant does not match file name [#27](https://github.com/streaming-video-technology-alliance/common-media-library/issues/27)
- lint errors when using typedoc specific tags [#32](https://github.com/streaming-video-technology-alliance/common-media-library/issues/32)
- Allow imports with file extensions [#26](https://github.com/streaming-video-technology-alliance/common-media-library/issues/26)


## [0.4.4] - 2023-10-11

### Fixed
- Module not found: Error: Default condition should be last one [#22](https://github.com/streaming-video-technology-alliance/common-media-library/issues/22)

- Module not found: Error: Default condition should be last one [#22](https://github.com/streaming-video-technology-alliance/common-media-library/issues/22)

## [0.4.3] - 2023-07-25

### Added

- Add `NOTICE` file for attributions
- Export library in cjs format [#11](https://github.com/streaming-video-technology-alliance/common-media-library/issues/11)

### Changed
- Switch to inline source maps

- Switch to inline source maps

## [0.4.2] - 2023-05-25

### Changed
- The project has moved to a new NPM org. First release under `@svta/common-media-library`.

- The project has moved to a new NPM org. First release under `@svta/common-media-library`.

## [0.4.1] - 2023-05-25

### Changed
- The project has moved to a new NPM org. Last release under `@svta.org/common-media-library`.

- The project has moved to a new NPM org. Last release under `@svta.org/common-media-library`.

## [0.4.0] - 2023-05-05

### Added
- Add ID3 APIs [#16](https://github.com/streaming-video-technology-alliance/common-media-library/issues/16)

- Add ID3 APIs [#16](https://github.com/streaming-video-technology-alliance/common-media-library/issues/16)

## [0.3.0] - 2023-05-04

### Added
- Add new decode APIs `fromCmcdHeaders` and `fromCmcdQuery`

- Add new decode APIs `fromCmcdHeaders` and `fromCmcdQuery`

## [0.2.6] - 2023-05-03

### Fixed
- Fix issue where `decodeCmcd` produces incorrect results for token values

- Fix issue where `decodeCmcd` produces incorrect results for token values

## [0.2.5] - 2023-05-03

### Fixed
- Fix issue where `decodeCmcd` produces incorrect results for empty strings

- Fix issue where `decodeCmcd` produces incorrect results for empty strings

## [0.2.4] - 2023-05-03

### Changed

- Update npm dependencies
- Improve `uuid` randomness
- Streamline build processes
- Update README


## [0.2.3] - 2023-05-03

### Added
- Export `CmcdParam`

- Export `CmcdParam`

## [0.2.2] - 2023-05-02

### Fixed
- Argument order mismatch in `appendCmcdQuery`

- Argument order mismatch in `appendCmcdQuery`

## [0.2.1] - 2023-05-02

### Added
- Additional formatting of CMCD integer values

- Additional formatting of CMCD integer values

## [0.2.0] - 2023-04-28

### Added

- Add namespaced exports

### Changed
- Update CMCD APIs

- Update CMCD APIs

## [0.1.2] - 2023-04-28

### Fixed
- Republish of NPM package

- Republish of NPM package

## [0.1.1] - 2023-04-27

### Added
- Add CMCD encode and decode APIs [#1](https://github.com/streaming-video-technology-alliance/common-media-library/issues/1)

- Add CMCD encode and decode APIs [#1](https://github.com/streaming-video-technology-alliance/common-media-library/issues/1)

## [0.1.0] - 2023-04-27

### Added
- Bootstrap project [#2](https://github.com/streaming-video-technology-alliance/common-media-library/issues/2)

- Bootstrap project [#2](https://github.com/streaming-video-technology-alliance/common-media-library/issues/2)

[Unreleased]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.6.2...HEAD
[0.6.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.6.1...v0.6.2
[0.6.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.6.0...v0.6.1
[0.6.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.5.1...v0.6.0
[0.5.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.5.0...v0.5.1
[0.5.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.5...v0.5.0
[0.4.5]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.4...v0.4.5
[0.4.4]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.3...v0.4.4
[0.4.3]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.2...v0.4.3
[0.4.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.1...v0.4.2
[0.4.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.0...v0.4.1
[0.4.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.3.0...v0.4.0
[0.3.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.6...v0.3.0
[0.2.6]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.5...v0.2.6
[0.2.5]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.4...v0.2.5
[0.2.4]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.3...v0.2.4
[0.2.3]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.2...v0.2.3
[0.2.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.1...v0.2.2
[0.2.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.0...v0.2.1
[0.2.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.2...v0.2.0
[0.1.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.1...v0.1.2
[0.1.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.0...v0.1.1
[0.1.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.0.0...v0.1.0
[Unreleased]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.6.2...HEAD
[0.6.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.6.1...v0.6.2
[0.6.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.6.0...v0.6.1
[0.6.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.5.1...v0.6.0
[0.5.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.5.0...v0.5.1
[0.5.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.5...v0.5.0
[0.4.5]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.4...v0.4.5
[0.4.4]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.3...v0.4.4
[0.4.3]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.2...v0.4.3
[0.4.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.1...v0.4.2
[0.4.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.0...v0.4.1
[0.4.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.3.0...v0.4.0
[0.3.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.6...v0.3.0
[0.2.6]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.5...v0.2.6
[0.2.5]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.4...v0.2.5
[0.2.4]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.3...v0.2.4
[0.2.3]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.2...v0.2.3
[0.2.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.1...v0.2.2
[0.2.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.0...v0.2.1
[0.2.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.2...v0.2.0
[0.1.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.1...v0.1.2
[0.1.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.0...v0.1.1
[0.1.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.0.0...v0.1.0
9 changes: 6 additions & 3 deletions lib/src/id3/getId3Frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { isId3Footer } from './util/isId3Footer.js';
import { isId3Header } from './util/isId3Header.js';
import { readId3Size } from './util/readId3Size.js';

const HEADER_FOOTER_SIZE = 10;
const FRAME_SIZE = 10;

/**
* Returns an array of ID3 frames found in all the ID3 tags in the id3Data
*
Expand All @@ -24,10 +27,10 @@ export function getId3Frames(id3Data: Uint8Array): Id3Frame[] {
while (isId3Header(id3Data, offset)) {
const size = readId3Size(id3Data, offset + 6);
// skip past ID3 header
offset += 10;
offset += HEADER_FOOTER_SIZE;
const end = offset + size;
// loop through frames in the ID3 tag
while (offset + 8 < end) {
while (offset + FRAME_SIZE < end) {
const frameData: RawId3Frame = getId3FrameData(id3Data.subarray(offset));
const frame: Id3Frame | undefined = decodeId3Frame(frameData);
if (frame) {
Expand All @@ -39,7 +42,7 @@ export function getId3Frames(id3Data: Uint8Array): Id3Frame[] {
}

if (isId3Footer(id3Data, offset)) {
offset += 10;
offset += HEADER_FOOTER_SIZE;
}
}

Expand Down
23 changes: 23 additions & 0 deletions lib/test/id3/decodeId3TextFrame.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { equal } from 'node:assert';
import { describe, it } from 'node:test';
import { decodeId3TextFrame } from '../../src/id3/util/decodeId3TextFrame.js';
import { Id3Frame } from '../../src/id3';

describe('decodeId3TextFrame', () => {
it('should decode a TXXX frame', () => {
const frame = {
type: 'TXXX',
data: new Uint8Array([0, 102, 111, 111, 0, 97, 98, 99]),
size: 2, // required by the decodeTextFrame function
};

const testables = {
decodeId3TextFrame: decodeId3TextFrame,
};

const result: Id3Frame | undefined = testables.decodeId3TextFrame(frame);
equal(result!.key, 'TXXX');
equal(result!.info, 'foo');
equal(result!.data, 'abc');
});
});
30 changes: 30 additions & 0 deletions lib/test/id3/isId3Footer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { equal } from 'node:assert';
import { describe, it } from 'node:test';
import { isId3Footer } from '../../src/id3/util/isId3Footer.js';

const LEADING_BYTE_SIZE = 8;
const TRAILING_BYTE_SIZE = 8;

describe('isId3Footer', () => {
const mockID3Footer = Uint8Array.from([
0x33, 0x44, 0x49, 4, 0, 0, 0, 0, 0, 63, 80, 82, 73, 86, 0, 0, 0, 53, 0, 0,
99, 111, 109, 46, 97, 112, 112, 108, 101, 46, 115, 116, 114, 101, 97, 109,
105, 110, 103, 46, 116, 114, 97, 110, 115, 112, 111, 114, 116, 83, 116, 114,
101, 97, 109, 84, 105, 109, 101, 115, 116, 97, 109, 112, 0, 0, 0, 0, 0, 0,
13, 198, 135,
]);
const mockID3FooterMissingLeadingByte = mockID3Footer.slice(
LEADING_BYTE_SIZE,
mockID3Footer.length
);
const mockID3FooterMissingTrailingByte = mockID3Footer.slice(
0,
mockID3Footer.length - TRAILING_BYTE_SIZE
);

it('Properly parses ID3 Footers', () => {
equal(isId3Footer(mockID3Footer, 0), true);
equal(isId3Footer(mockID3FooterMissingLeadingByte, 0), false);
equal(isId3Footer(mockID3FooterMissingTrailingByte, 0), true);
});
});
30 changes: 30 additions & 0 deletions lib/test/id3/isId3Header.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { equal } from 'node:assert';
import { describe, it } from 'node:test';
import { isId3Header } from '../../src/id3/util/isId3Header.js';

const LEADING_BYTE_SIZE = 8;
const TRAILING_BYTE_SIZE = 8;

describe('isId3Header', () => {
const mockID3Header = Uint8Array.from([
73, 68, 51, 4, 0, 0, 0, 0, 0, 63, 80, 82, 73, 86, 0, 0, 0, 53, 0, 0, 99,
111, 109, 46, 97, 112, 112, 108, 101, 46, 115, 116, 114, 101, 97, 109, 105,
110, 103, 46, 116, 114, 97, 110, 115, 112, 111, 114, 116, 83, 116, 114, 101,
97, 109, 84, 105, 109, 101, 115, 116, 97, 109, 112, 0, 0, 0, 0, 0, 0, 13,
198, 135,
]);
const mockID3HeaderMissingLeadingByte = mockID3Header.slice(
LEADING_BYTE_SIZE,
mockID3Header.length
);
const mockID3HeaderMissingTrailingByte = mockID3Header.slice(
0,
mockID3Header.length - TRAILING_BYTE_SIZE
);

it('Properly parses ID3 Headers', () => {
equal(isId3Header(mockID3Header, 0), true);
equal(isId3Header(mockID3HeaderMissingLeadingByte, 0), false);
equal(isId3Header(mockID3HeaderMissingTrailingByte, 0), true);
});
});
10 changes: 10 additions & 0 deletions lib/test/id3/readId3Size.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { equal } from 'node:assert';
import { describe, it } from 'node:test';
import { readId3Size } from '../../src/id3/util/readId3Size.js';

describe('readId3Size', () => {
const mockID3SizeData = Uint8Array.from([73, 68, 51, 4, 0, 0, 0, 7, 1, 0]);
it('returns Id3 size', () => {
equal(readId3Size(mockID3SizeData, 6), 114816);
});
});
Loading