Skip to content

Commit

Permalink
Reintroduced id3 tests but using common media library
Browse files Browse the repository at this point in the history
Signed-off-by: coatesjuan <juanco@qualabs.com>
  • Loading branch information
coatesjuan committed Feb 27, 2024
1 parent fc0484b commit 57203a7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
21 changes: 20 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,8 @@
"typescript": "5.3.3",
"url-toolkit": "2.2.5",
"wrangler": "3.24.0"
},
"dependencies": {
"ci": "^2.3.0"
}
}
44 changes: 44 additions & 0 deletions tests/unit/demuxer/id3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import { canParseId3 } from '@svta/common-media-library/id3/canParseId3';
import { Id3Frame } from '@svta/common-media-library/id3/Id3Frame';
import { isId3Header } from '@svta/common-media-library/id3/util/isId3Header';
import { expect } from 'chai';
import { utf8ArrayToStr } from '../../../src/demux/id3';
import { decodeId3TextFrame } from '@svta/common-media-library/id3/util/decodeId3TextFrame';

describe('ID3 tests', function () {
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(
8,
mockID3Header.length,
);
const mockID3HeaderMissingTrailingByte = mockID3Header.slice(
0,
mockID3Header.length - 8,
);

it('utf8ArrayToStr', function (done) {
const aB = new Uint8Array([97, 98]);
const aNullBNullC = new Uint8Array([97, 0, 98, 0, 99]);
Expand All @@ -12,4 +32,28 @@ describe('ID3 tests', function () {

done();
});
it('Properly parses ID3 Headers', function () {
expect(isId3Header(mockID3HeaderMissingLeadingByte, 0)).to.equal(false);
expect(isId3Header(mockID3HeaderMissingTrailingByte, 0)).to.equal(true);
expect(isId3Header(mockID3Header, 0)).to.equal(true);
});
it('Properly parses ID3 Info', function () {
expect(canParseId3(mockID3Header, 0)).to.equal(true);
expect(canParseId3(mockID3HeaderMissingLeadingByte, 0)).to.equal(false);
expect(canParseId3(mockID3HeaderMissingTrailingByte, 0)).to.equal(false);
});

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

const result: Id3Frame | undefined = decodeId3TextFrame(frame);
expect(result).to.exist;
expect(result!.key).to.equal('TXXX');
expect(result!.info).to.equal('foo');
expect(result!.data).to.equal('abc');
});
});

0 comments on commit 57203a7

Please sign in to comment.